/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
if (! function_exists('config')) {
/**
* Get / set the specified configuration value.
*
* If an array is passed as the key, we will assume you want to set an array of values.
*
* @param array|string $key
* @param mixed $default
* @return mixed
*/
function config($key = null, $default = null)
{
if (is_null($key)) {
return app('config');
}
if (is_array($key)) {
return app('config')->set($key);
}
return app('config')->get($key, $default);
}
}
问题:
代码如上. 这里的set()和get()都是function, 但是app('config')返回的instance中没有对应的get()和set()方法,也没有__call()的方法重载.那这里的get()和set()是怎么实现的呢?
在app('config')返回的instance中倒是有__set() 和 __get(), 但是这两个不是属性重载吗?
app('config')
返回的是Illuminate\Config\Repository
,有get()
和set()
。