<?php namespace Illuminate\Support\Facades; /** * @see \Illuminate\Auth\AuthManager * @see \Illuminate\Auth\Guard */ class Auth extends Facade { /** * Get the registered name of the component. * * @return string */ protected static function getFacadeAccessor() { return 'auth'; } }
[auth]的注册
<?php namespace Illuminate\Auth; use Illuminate\Support\ServiceProvider; class AuthServiceProvider extends ServiceProvider { protected function registerAuthenticator() { $this->app->singleton('auth', function ($app) { // Once the authentication service has actually been requested by the developer // we will set a variable in the application indicating such. This helps us // know that we need to set any queued cookies in the after event later. $app['auth.loaded'] = true; return new AuthManager($app); }); $this->app->singleton('auth.driver', function ($app) { return $app['auth']->driver(); }); } }
由于不存在这个方法
Illuminate\Auth\AuthManager->guest()
所以调用父类的以下方法
<?php namespace Illuminate\Support; use Closure; use InvalidArgumentException; abstract class Manager { public function __call($method, $parameters) { return call_user_func_array([$this->driver(), $method], $parameters); } }
$this->driver()也就是
public function driver($driver = null) { $driver = $driver ?: $this->getDefaultDriver(); // If the given driver has not been created before, we will create the instances // here and cache it so we can return it next time very quickly. If there is // already a driver created by this name, we'll just return that instance. if (!isset($this->drivers[$driver])) { $this->drivers[$driver] = $this->createDriver($driver); } return $this->drivers[$driver]; }
$this->getDefaultDriver()也就是
<?php namespace Illuminate\Auth; use Illuminate\Support\Manager; class AuthManager extends Manager { public function getDefaultDriver() { return $this->app['config']['auth.driver']; } }
$this->app['config']['auth.driver'];其实就是config目录下,auth.php文件的driver设值
<?php return [ 'driver' => 'eloquent',
那么上面的$this->createDriver($driver);就是
<?php namespace Illuminate\Support; use Closure; use InvalidArgumentException; abstract class Manager { */ protected function createDriver($driver) { $method = 'create'.ucfirst($driver).'Driver'; // We'll check to see if a creator method exists for the given driver. If not we // will check for a custom driver creator, which allows developers to create // drivers using their own customized driver creator Closure to create it. if (isset($this->customCreators[$driver])) { return $this->callCustomCreator($driver); } elseif (method_exists($this, $method)) { return $this->$method(); } throw new InvalidArgumentException("Driver [$driver] not supported."); } }
也就是
<?php namespace Illuminate\Auth; use Illuminate\Support\Manager; class AuthManager extends Manager { /** * Create an instance of the Eloquent driver. * * @return \Illuminate\Auth\Guard */ public function createEloquentDriver() { $provider = $this->createEloquentProvider(); return new Guard($provider, $this->app['session.store']); } }
所以auth最终就是Guard
相关推荐
Laravel开发-facade-resolver 用于将外观名称解析为实际类名的laravel命令
Laravel开发-laravel-facade-dump 创建Laravel立面结构的JSON转储。用于生成最新的备忘单
Laravel开发-symfonys-facade 为Laravel框架设计的symfonys立面。
laravel-cart, Laravel Facade和MoltinCart服务提供程序 这里正在考虑转移所有权,请在这里看到: https://github.com/moltin/laravel-cart/issues/62#issuecomment-328447136 Laravel 购物车包Laravel Facad
设计模式1,FACADE模式,Adapter facade Adapter singleton proxy
设计模式之门面模式(Facade模式),介绍门面模式,实际例子分析,代码讲解等
将facade类设置成接口,应用facade模式的一个小程序,易于理解,附带类图
Facade其实是一个容器中类的静态代理,他可以让你以静态的方式来调用存放在容器中任何对象的任何方法,下面这篇文章主要给大家介绍了关于Laravel中Facade的加载过程与原理的相关资料,需要的朋友可以参考下。
Laravel开发-laravel-medoo Laravel Facade和ServiceProvider,用于最轻的PHP数据库框架,以加速开发
主要介绍了laravel5创建service provider和facade的方法,实例分析了laravel创建service、provider和facade类的具体步骤与实现技巧,需要的朋友可以参考下
23种设计模式之十一(结构型模式)Facade模式
用于Goutte的Laravel Facade此存储库实现了一个简单的ServiceProvider,可通过Laravel中的Facade轻松访问Goutte客户端的单例实例。 有关适用于Goutte的Laravel Facade的更多信息,请参见@ FriendsOfPHP / Goutte。此...
Laravel开发-medoo-laravel Laravel Facade和ServiceProvider,用于最轻的PHP数据库框架,以加速开发
eclipse工程文件 包含代码 有助理解 门面(Facade)模式 <br>外部与一个子系统的通信必须通过一个统一的门面(Facade)对象进行,这就是门面模式。 <br>医院的例子 <br>用一个例子进行说明,如果把医院...
在这里与各位分享本人从网络上下载的C#面向对象设计模式纵横谈系列视频,共有25节,除了第一节需要各位贡献一点资源分以作为对本人上传资源的回馈,后面的其他资源均不需要资源分。敬请期待。 这是第11节:结构型...
为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
基于Facade的EJB远程调用技术 基于Facade的EJB远程调用技术
在书中,作者们将这二十三种设计模式分成了三类,分别是创建型模式、结构型模式和行为型模式。 创建型模式包含了: 工厂方法模式( Factory Method ) ...书中通过一幅图,剖析了这二十三种设计模式的关系。
23种设计模式的java实现之Facade模式,代码实现,可以参考