Laravel 4难以跟踪方法的位置

时间:2017-04-21 11:07:42

标签: php laravel-4

我使用PHPStorm,如果它有方法可以提供帮助,我也可以在Mac OSX系统上使用。

我们的代码中包含以下行:

$config = Config::get('regions');

首先,我想找到class Config的位置。好吧,这不会起作用..

print_r(get_class(Config));

所以我这样做:

$test = new Config; //works
print_r(get_class(Config));

这给了我:

\Illuminate\Support\Facades\Config

反过来又很短:

<?php namespace Illuminate\Support\Facades;

/**
 * @see \Illuminate\Config\Repository
 */
class Config extends Facade {

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor() { return 'config'; }

}

所以..我查看Facade没有get()方法。

在代码中搜索function get(..,其中有超过100个实例。

我如何在世界上找到这种特定的get()方法?

1 个答案:

答案 0 :(得分:1)

Laravel使用Facades提供静态界面。基本上它们是物体的快捷方式。服务容器中的变量。

查看Laravel 4.2 Facades documentation

Laravel的功能是允许您使用静态呼叫:

Config::get('x');

它从Facade类提供的密钥下的服务容器中解析它。对于Config,这是'config'

在Laravel 5.4中,它在以下容器中注册到容器中: SRC /照亮/粉底/ start.php

/*
|--------------------------------------------------------------------------
| Register The Configuration Repository
|--------------------------------------------------------------------------
|
| The configuration repository is used to lazily load in the options for
| this application from the configuration files. The files are easily
| separated by their concerns so they do not become really crowded.
|
*/

$app->instance('config', $config = new Config(

    $app->getConfigLoader(), $env

));

你会在同一个文件中注意到这一点:

use Illuminate\Config\Repository as Config;

因此,您要查找的课程为Illuminate\Config\Repository,其中get()方法。

这也是Facade本身暗示的内容;)

/**
 * @see \Illuminate\Config\Repository
 */

一些Facade在框架内处理,其他一些由ServiceProviders在应用程序本身中提供,您可以从中找到它们绑定到容器的类。