2017-04-21 29 views
0

我使用PHPStorm,如果它有幫助的方法,我也在Mac OSX系統上。Laravel 4有難以跟蹤方法的位置

我們已經在我們下面的一行代碼:

$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()方法?

+0

爲什麼你需要它?此方法只是從app/config文件夾中的文件regions.php返回內容。 –

+0

雖然我很欣賞貢獻,但這不是我問的問題。在某些情況下,未來某些開發人員(如我自己)可能想知道如何找到特定方法或其他特定方法。 –

回答

1

Laravel使用Facades來提供靜態接口。基本上它們是服務容器中變量的對象&的快捷方式。

退房Laravel 4.2 Facades documentation

什麼Laravel所做的是讓您在使用一個靜態調用:

Config::get('x'); 

它由門面類提供的鍵下解決它從服務容器。對於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()方法。

這也是什麼門面本身暗示過;)

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

一些外牆的是框架內處理,另一些由ServiceProviders在應用程序本身,從中你可以找到提供它們綁定到容器的哪個類。

+0

謝謝。我確實看到了@see提示,但由於某種原因(可能是用戶錯誤:)我沒有找到'get()'方法,可能在錯誤的地方查找。 –