phplaravelfacade

Laravel: how to find concrete implementation of a Facade?


This is the link to source code of Laravel (v8 but it's not important) about Redis Facade

https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Facades/Facade.php#L164

I would like to find the 'concrete' Redis class served by the facade itself.

How can I do? Where does Laravel framework bind this facade to a "real" class?


Solution

  • Concrete implementation of a Facade in Laravel is served from the service container.

    For Redis you can find in vendor/laravel/framework/src/Illuminate/Redis/RedisServiceProvider.php

    In Laravel 9.3 you can see something like this

    public function register()
    {
        $this->app->singleton('redis', function ($app) {
            $config = $app->make('config')->get('database.redis', []);
    
            return new RedisManager($app, Arr::pull($config, 'client', 'phpredis'), $config);
        });
    
        $this->app->bind('redis.connection', function ($app) {
            return $app['redis']->connection();
        });
    }
    

    RedisManager is the concrete implementation of the Redis. Whenever you call methods on the Redis, you're calling methods on the RedisManager only.