mercredi 30 septembre 2015

Overridden core class does not work when in artisan

In a fresh Laravel build, I cannot get overridden IoC bindings to work everywhere in the application.

Suppose a service provider that overrides a core class, e.g. cache:

class NewServiceProvider extends ServiceProvider
{
    protected $defer = true;

    public function register()
    {
        $this->app->bind('cache', function($app) {
            return new \stdClass; // demo purpose
        });
    }

    public function provides()
       {
        return ['cache'];
    }
}

The provider is then added at the bottom of app.providers config.

Now modify routes.php to the following and go check the result:

Route::get('/', function () {
    dd(app('cache'));
});

// Results in an empty stdClass being shown. It works!

However, fire up artisan tinker and do the same:

$ php artisan tinker
>>> app('cache')
=> Illuminate\Cache\CacheManager

Suddenly the override isn't working anymore...

The same behavior is encountered when processing event listeners...

Is this normal behavior and am I overlooking something? Or is this some kind of bug?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1GjjyCp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire