2016-04-09 118 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 - 因为这个方法返回请求的对象。