本文使用版本为laravel5.5
cache get
1 | public function cache() |
config/app.php
1 | 'aliases' => [ |
使用cache实际调用的是Illuminate\Support\Facades\Cache
,这个映射是如何做的?
public/index.php
1 | $response = $kernel->handle( |
bootstarp/app.php
1 | $app->singleton( |
app/http/kernel.php
1 | use Illuminate\Foundation\Http\Kernel as HttpKernel; |
Illuminate/Foundation/Http/Kernel.php
1 | public function handle($request) |
Illuminate/Foundation/Application.php
1 | public function bootstrapWith(array $bootstrappers) |
Illuminate/Foundation/Bootstrap/RegisterFacades.php
1 | public function bootstrap(Application $app) |
Illuminate/Foundation/AliasLoader.php
1 | public function load($alias) |
Illuminate/Support/Facades/Cache.php
1 | class Cache extends Facade |
Illuminate/Support/Facades/Facade.php
这个文件没有get set ,只有__callStatic1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
if (! $instance) {
throw new RuntimeException('A facade root has not been set.');
}
return $instance->$method(...$args);
}
public static function getFacadeRoot()
{
return static::resolveFacadeInstance(static::getFacadeAccessor());
}
protected static function resolveFacadeInstance($name)
{
//这里$name为cache
if (is_object($name)) {
return $name;
}
if (isset(static::$resolvedInstance[$name])) {
return static::$resolvedInstance[$name];
}
//$app是容器对象,实现了ArrayAccess接口,最终调用的还是容器的make方法
return static::$resolvedInstance[$name] = static::$app[$name];
}
Illuminate\Container\Container.php
1 | public function make($abstract, array $parameters = []) |
Illuminate/Cache/CacheServiceProvider.php
1 | public function register() |
get set
1 | $instance->$method(...$args) |
Laravel 源码阅读之二:Illuminate\Foundation\Application 类初始化分析