每天laravel-20160708|Repository
2016-04-08 09:03
405 查看
<?php namespace Illuminate\Config; use ArrayAccess; use Illuminate\Support\Arr; use Illuminate\Contracts\Config\Repository as ConfigContract; // a knowledge library ,that is a namespace class Repository implements ArrayAccess, ConfigContract { /** * All of the configuration items. * * @var array */ protected $items = [];// all of the configuration items. /** * Create a new configuration repository. * * @param array $items * @return void */ public function __construct(array $items = []) { $this->items = $items; }// a construct function about the repository. // create a new configuration repository /** * Determine if the given configuration value exists. * * @param string $key * @return bool */ public function has($key) { return Arr::has($this->items, $key); }// use a static method /** * Get the specified configuration value. * * @param string $key * @param mixed $default * @return mixed */ public function get($key, $default = null) { return Arr::get($this->items, $key, $default); }// Get the specified configuration value. /** * Set a given configuration value. * * @param array|string $key * @param mixed $value * @return void */ public function set($key, $value = null) { if (is_array($key)) {// more get many get foreach ($key as $innerKey => $innerValue) {// set the keys Arr::set($this->items, $innerKey, $innerValue); } } else {// single set Arr::set($this->items, $key, $value); } }// Set a given configuration value /** * Prepend a value onto an array configuration value. * * @param string $key * @param mixed $value * @return void */ public function prepend($key, $value)// Prepend a value onto an array configuration value. { $array = $this->get($key);// get way to get value by key array_unshift($array, $value);// insert a value to the array by key in th first place $this->set($key, $array);// set key } /** * Push a value onto an array configuration value. * * @param string $key * @param mixed $value * @return void */ public function push($key, $value) { $array = $this->get($key); $array[] = $value; $this->set($key, $array); }// push a value onto an array configuration value. // insert into the last key /** * Get all of the configuration items for the application. * * @return array */ public function all() { return $this->items; }// get all the items[] array /** * Determine if the given configuration option exists. * * @param string $key * @return bool */ public function offsetExists($key) { return $this->has($key); }// check has the key /** * Get a configuration option. * * @param string $key * @return mixed */ public function offsetGet($key) { return $this->get($key); }// get a value by key /** * Set a configuration option. * * @param string $key * @param mixed $value * @return void */ public function offsetSet($key, $value) { $this->set($key, $value); }// set/ add/ a option /** * Unset a configuration option. * * @param string $key * @return void */ public function offsetUnset($key) { $this->set($key, null); }// delete a item[option] }
相关文章推荐
- PHP中foreach循环传值问题
- PHP中__autoload和Smarty冲突的简单解决方法
- PHP调试及IDE环境
- thinkphp3.2.3分页代码
- add2array.php
- PHP命名空间namespace使用小结
- php的tips(数组排序函数)
- 初识PHP(二)常用函数
- php实习的tips(结束符的问题)
- php的tips(接口结束符问题)
- laravel学习(一)-laravel安装
- php 字符串函数汇总
- php使用ajax中文乱码问题
- PHP中__autoload和Smarty冲突的简单解决方法
- PHP使用PDO操作数据库的乱码问题解决方法
- php生成带logo二维码方法小结
- PHP实现基于mysqli的Model基类完整实例
- PHP文件上传类实例详解
- PHP实现简单实用的分页类代码
- IIS+PHP环境下文件上传无法访问问题