php - laravel中config方法的get与set

查看:165
本文介绍了php - laravel中config方法的get与set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

/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()

这篇关于php - laravel中config方法的get与set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆