2016-04-09 57 views
1

你好我可以在laravel框架Laravel類驗證

namespace Illuminate\Support\Facades; 

/** 
* @see \Illuminate\Auth\AuthManager 
* @see \Illuminate\Contracts\Auth\Factory 
* @see \Illuminate\Contracts\Auth\Guard 
* @see \Illuminate\Contracts\Auth\StatefulGuard 
*/ 
class Auth extends Facade 
{ 
    /** 
    * Get the registered name of the component. 
    * 
    * @return string 
    */ 
    protected static function getFacadeAccessor() 
    { 
     return 'auth'; 
    } 
} 

問這是什麼回報「權威性」正好返回給調用?它是文本'auth'還是一個對象?那他們爲什麼只有一種方法的原因是什麼?我很抱歉,我只是在學習oop。

預先感謝您。

+0

它在它將作爲字符串返回的引號中。 –

+0

並等待這個問題返回'auth'返回給調用者的是什麼? –

回答

2

在這種情況下,您會看到方法​​它返回auth字符串。

外牆只是使用其他類的「捷徑」,但實際上,如果不需要,不應在任何地方使用它們。

在Laravel中,您可以將對象/類綁定到應用程序中。所以,你可以寫例如:

$app->bind('something', function() { 
    return new SomeObject(); 
}); 

假設有方法doSomethingSomeObject類。

現在你可以使用這個方法使用:

$app['something']->doSomething(); 

但你也可以創建門面:

class GreatClass extends Facade 
{ 
    /** 
    * Get the registered name of the component. 
    * 
    * @return string 
    */ 
    protected static function getFacadeAccessor() 
    { 
     return 'something'; 
    } 
} 

,現在在你的應用程序的任何地方,你可以使用:

GreatClass::doSomething(); 

回答你的問題​​只返回名稱使用的對象的名稱當綁定到應用程序。要知道如何使用它,你可以看看源:

/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php

你應該看看第一個方法是getFacadeRoot - 因爲這個方法返回請求的對象。