成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

laravel cache get 是如何調(diào)用的?

solocoder / 3063人閱讀

摘要:本文使用版本為使用實(shí)際調(diào)用的是這個(gè)映射是如何做的將里的數(shù)組里面的類(lèi)設(shè)置別名來(lái)自于中數(shù)組為一個(gè)類(lèi)創(chuàng)建別名這個(gè)文件沒(méi)有,只有這里為是容器對(duì)象,實(shí)現(xiàn)了接口,最終調(diào)用的還是容器的方法

本文使用版本為laravel5.5

cache get
public function cache()
    {
        $c=Cache::get("app");
        if(!$c) {
            Cache::put("app", "cache", 1);
        }
        dump($c);//cache
    }
    
config/app.php
 "aliases" => [

        "App" => IlluminateSupportFacadesApp::class,
        "Artisan" => IlluminateSupportFacadesArtisan::class,
        "Auth" => IlluminateSupportFacadesAuth::class,
        "Blade" => IlluminateSupportFacadesBlade::class,
        "Broadcast" => IlluminateSupportFacadesBroadcast::class,
        "Bus" => IlluminateSupportFacadesBus::class,
        "Cache" => IlluminateSupportFacadesCache::class,
        
        ]

使用cache實(shí)際調(diào)用的是IlluminateSupportFacadesCache,這個(gè)映射是如何做的?

public/index.php
$response = $kernel->handle(
$request = IlluminateHttpRequest::capture()
);
bootstarp/app.php
$app->singleton(
    IlluminateContractsHttpKernel::class,
    AppHttpKernel::class
);
app/http/kernel.php
use IlluminateFoundationHttpKernel as HttpKernel;

class Kernel extends HttpKernel
{

}
Illuminate/Foundation/Http/Kernel.php
public function handle($request)
{
    try {
        $request->enableHttpMethodParameterOverride();
        $response = $this->sendRequestThroughRouter($request);
    } catch (Exception $e) {
        $this->reportException($e);

        $response = $this->renderException($request, $e);
    } catch (Throwable $e) {
        $this->reportException($e = new FatalThrowableError($e));

        $response = $this->renderException($request, $e);
    }

    $this->app["events"]->dispatch(
        new EventsRequestHandled($request, $response)
    );

    return $response;
}
protected function sendRequestThroughRouter($request)
    {
        $this->app->instance("request", $request);

        Facade::clearResolvedInstance("request");

        $this->bootstrap();

        return (new Pipeline($this->app))
                    ->send($request)
                    ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
                    ->then($this->dispatchToRouter());
    }
    public function bootstrap()
    {
        if (! $this->app->hasBeenBootstrapped()) {
            $this->app->bootstrapWith($this->bootstrappers());
        }
    }
Illuminate/Foundation/Application.php
public function bootstrapWith(array $bootstrappers)
    {
        $this->hasBeenBootstrapped = true;

        foreach ($bootstrappers as $bootstrapper) {
            $this["events"]->fire("bootstrapping: ".$bootstrapper, [$this]);

            $this->make($bootstrapper)->bootstrap($this);

            $this["events"]->fire("bootstrapped: ".$bootstrapper, [$this]);
        }
    }
Illuminate/Foundation/Bootstrap/RegisterFacades.php
public function bootstrap(Application $app)
    {
        Facade::clearResolvedInstances();

        Facade::setFacadeApplication($app);
//將config/app.php 里的aliases數(shù)組里面的Facades類(lèi)設(shè)置別名
        AliasLoader::getInstance(array_merge(
            $app->make("config")->get("app.aliases", []),
            $app->make(PackageManifest::class)->aliases()
        ))->register();
    }
Illuminate/Foundation/AliasLoader.php
public function load($alias)
    {
        if (static::$facadeNamespace && strpos($alias, static::$facadeNamespace) === 0) {
            $this->loadFacade($alias);

            return true;
        }

      // $alias來(lái)自于config/app.php中aliases數(shù)組 
        if (isset($this->aliases[$alias])) {
            //"Route" => IlluminateSupportFacadesRoute::class,
            // class_alias 為一個(gè)類(lèi)創(chuàng)建別名
            return class_alias($this->aliases[$alias], $alias);
        }
    }
Illuminate/Support/Facades/Cache.php
class Cache extends Facade
{
    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return "cache";
    }
}
Illuminate/Support/Facades/Facade.php

這個(gè)文件沒(méi)有g(shù)et set ,只有__callStatic

public 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是容器對(duì)象,實(shí)現(xiàn)了ArrayAccess接口,最終調(diào)用的還是容器的make方法
        return static::$resolvedInstance[$name] = static::$app[$name];
    }
IlluminateContainerContainer.php
public function make($abstract, array $parameters = [])
    {
        return $this->resolve($abstract, $parameters);
    }
    protected function resolve($abstract, $parameters = [])
    {
        $abstract = $this->getAlias($abstract);

        $needsContextualBuild = ! empty($parameters) || ! is_null(
            $this->getContextualConcrete($abstract)
        );

        // If an instance of the type is currently being managed as a singleton we"ll
        // just return an existing instance instead of instantiating new instances
        // so the developer can keep using the same objects instance every time.
        if (isset($this->instances[$abstract]) && ! $needsContextualBuild) {
            return $this->instances[$abstract];
        }

        $this->with[] = $parameters;

        $concrete = $this->getConcrete($abstract);

        // We"re ready to instantiate an instance of the concrete type registered for
        // the binding. This will instantiate the types, as well as resolve any of
        // its "nested" dependencies recursively until all have gotten resolved.
        if ($this->isBuildable($concrete, $abstract)) {
            $object = $this->build($concrete);
        } else {
            $object = $this->make($concrete);
        }

        // If we defined any extenders for this type, we"ll need to spin through them
        // and apply them to the object being built. This allows for the extension
        // of services, such as changing configuration or decorating the object.
        foreach ($this->getExtenders($abstract) as $extender) {
            $object = $extender($object, $this);
        }

        // If the requested type is registered as a singleton we"ll want to cache off
        // the instances in "memory" so we can return it later without creating an
        // entirely new instance of an object on each subsequent request for it.
        if ($this->isShared($abstract) && ! $needsContextualBuild) {
            $this->instances[$abstract] = $object;
        }

        $this->fireResolvingCallbacks($abstract, $object);

        // Before returning, we will also set the resolved flag to "true" and pop off
        // the parameter overrides for this build. After those two things are done
        // we will be ready to return back the fully constructed class instance.
        $this->resolved[$abstract] = true;

        array_pop($this->with);

        return $object;
    }
Illuminate/Cache/CacheServiceProvider.php
 public function register()
    {
        $this->app->singleton("cache", function ($app) {
            return new CacheManager($app);
        });

        $this->app->singleton("cache.store", function ($app) {
            return $app["cache"]->driver();
        });

        $this->app->singleton("memcached.connector", function () {
            return new MemcachedConnector;
        });
    }
get set
$instance->$method(...$args)

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/29907.html

相關(guān)文章

  • Laravel學(xué)習(xí)筆記之Session源碼解析(上)

    摘要:然后中間件使用方法來(lái)啟動(dòng)獲取實(shí)例,使用類(lèi)來(lái)管理主要分為兩步獲取實(shí)例,主要步驟是通過(guò)該實(shí)例從存儲(chǔ)介質(zhì)中讀取該次請(qǐng)求所需要的數(shù)據(jù),主要步驟是。 說(shuō)明:本文主要通過(guò)學(xué)習(xí)Laravel的session源碼學(xué)習(xí)Laravel是如何設(shè)計(jì)session的,將自己的學(xué)習(xí)心得分享出來(lái),希望對(duì)別人有所幫助。Laravel在web middleware中定義了session中間件IlluminateSess...

    NervosNetwork 評(píng)論0 收藏0
  • Laravel學(xué)習(xí)筆記之Filesystem源碼解析(下)

    摘要:源碼解析這個(gè)類(lèi)的源碼主要就是文件的操作和文件屬性的操作,而具體的操作是通過(guò)每一個(gè)實(shí)現(xiàn)的,看其構(gòu)造函數(shù)看以上代碼知道對(duì)于操作,實(shí)際上是通過(guò)的實(shí)例來(lái)實(shí)現(xiàn)的??梢钥聪碌氖褂蒙衔囊呀?jīng)說(shuō)了,使得對(duì)各種的操作變得更方便了,不管是還是得。 說(shuō)明:本文主要學(xué)習(xí)下LeagueFlysystem這個(gè)Filesystem Abstract Layer,學(xué)習(xí)下這個(gè)package的設(shè)計(jì)思想和編碼技巧,把自己的一...

    Luosunce 評(píng)論0 收藏0
  • 【譯】深入研究Laravel依賴(lài)注入容器

    摘要:原文地址下面是中文翻譯擁有強(qiáng)大的控制反轉(zhuǎn)依賴(lài)注入容器。單例在使用自動(dòng)綁定和時(shí),每次需要時(shí)都會(huì)創(chuàng)建一個(gè)新的實(shí)例或者調(diào)用閉包。 原文地址 Laravels Dependency Injection Container in Depth 下面是中文翻譯 Laravel擁有強(qiáng)大的控制反轉(zhuǎn)(IoC)/依賴(lài)注入(DI) 容器。不幸的是官方文檔并沒(méi)有涵蓋所有可用的功能,因此,我決定嘗試寫(xiě)文檔為自...

    chavesgu 評(píng)論0 收藏0
  • Laravel 模板引擎(Blade)原理簡(jiǎn)析

    摘要:上次提到過(guò),模板引擎一般是要做三件事情變量值的輸出條件判斷和循環(huán)引入或繼承其他文件現(xiàn)在就來(lái)看看的模板引擎是如何來(lái)處理這三件事情的。引擎接下來(lái)就是本文的重點(diǎn)是如何編譯的。如果有興趣的話(huà),也可以實(shí)現(xiàn)一個(gè)自己的模板解析引擎。 上次提到過(guò),模板引擎一般是要做三件事情: 變量值的輸出(echo) 條件判斷和循環(huán)(if ... else、for、foreach、while) 引入或繼承其他文件 ...

    vvpvvp 評(píng)論0 收藏0
  • Laravel學(xué)習(xí)筆記之bootstrap源碼解析

    摘要:總結(jié)本文主要學(xué)習(xí)了啟動(dòng)時(shí)做的七步準(zhǔn)備工作環(huán)境檢測(cè)配置加載日志配置異常處理注冊(cè)注冊(cè)啟動(dòng)。 說(shuō)明:Laravel在把Request通過(guò)管道Pipeline送入中間件Middleware和路由Router之前,還做了程序的啟動(dòng)Bootstrap工作,本文主要學(xué)習(xí)相關(guān)源碼,看看Laravel啟動(dòng)程序做了哪些具體工作,并將個(gè)人的研究心得分享出來(lái),希望對(duì)別人有所幫助。Laravel在入口index...

    xiaoxiaozi 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<