laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
474 stars 48 forks source link

Error Runing Pennant with Octane(Swoole) #55

Closed garissman closed 1 year ago

garissman commented 1 year ago

Description:

Only when running Laravel with octane $this->app[FeatureManager::class]->setContainer(Container::getInstance())=null so, in vendor/laravel/pennant/src/PennantServiceProvider->listenForEvents() crash,

Steps To Reproduce:

$ composer create-project laravel/laravel pennantOctane $ cd pennantOctane $ composer require laravel/octane $ php artisan octane:install I use swoole $ composer require laravel/pennant $ php artisan vendor:publish --provider="Laravel\Pennant\PennantServiceProvider" $ php artisan octane:start

INFO Server running…

Local: http://127.0.0.1:8000

Press Ctrl+C to stop the server

Error

Call to a member function flushCache() on null

at vendor/laravel/pennant/src/PennantServiceProvider.php:64 60▕ \Laravel\Octane\Events\TaskReceived::class, 61▕ \Laravel\Octane\Events\TickReceived::class, 62▕ ], fn () => $this->app[FeatureManager::class] 63▕ ->setContainer(Container::getInstance()) ➜ 64▕ ->flushCache()); 65▕ 66▕ $this->app['events']->listen([ 67▕ \Illuminate\Queue\Events\JobProcessed::class, 68▕ ], fn () => $this->app[FeatureManager::class]->flushCache());

I notice that Laravel\Pennant\FeatureManager::setContainer() return void so, it should return itself, to be able to call Laravel\Pennant\FeatureManager::flushCache(),

garissman commented 1 year ago

Hi @driesvints @timacdonald What other info you need? I'm here to help,

driesvints commented 1 year ago

@arimoralesjordan I've assigned Tim to review.

mbukovy commented 1 year ago

This is enough to fix this error https://github.com/laravel/pennant/pull/56/files I'm just not sure, whether flushCache should be called on TickReceived event of Octane, since it's like... every second?