<?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] }
每天laravel-20160708|Repository
原创lijingsan1 博主文章分类:php ©著作权
©著作权归作者所有:来自51CTO博客作者lijingsan1的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
laravel实现高并发限流解决方案之令牌桶算法
限流 laravel限流 高并发
php App redis