您的位置:首页 > 编程语言 > PHP开发

每天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]
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: