From 3c4e7172ae73de1bd700893427fb18a91ce99479 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 25 Jan 2022 19:40:13 +0000 Subject: [PATCH] [1.x] Flushes `Str` cache between requests (#468) * Flushes `Str` cache between requests * Bumps framework version --- composer.json | 2 +- .../ProvidesDefaultConfigurationOptions.php | 1 + src/Listeners/FlushStrCache.php | 19 +++++++++ tests/Listeners/FlushStrCacheTest.php | 39 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/Listeners/FlushStrCache.php create mode 100644 tests/Listeners/FlushStrCacheTest.php diff --git a/composer.json b/composer.json index 7fe496ab5..bb00262a6 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { "php": "^8.0", - "laravel/framework": "^8.77|^9.0", + "laravel/framework": "^8.81|^9.0", "laminas/laminas-diactoros": "^2.5", "laravel/serializable-closure": "^1.0", "symfony/psr-http-message-bridge": "^2.0" diff --git a/src/Concerns/ProvidesDefaultConfigurationOptions.php b/src/Concerns/ProvidesDefaultConfigurationOptions.php index dd3086274..b8c8f3bcf 100644 --- a/src/Concerns/ProvidesDefaultConfigurationOptions.php +++ b/src/Concerns/ProvidesDefaultConfigurationOptions.php @@ -50,6 +50,7 @@ public static function prepareApplicationForNextOperation(): array \Laravel\Octane\Listeners\FlushLogContext::class, \Laravel\Octane\Listeners\FlushArrayCache::class, \Laravel\Octane\Listeners\FlushMonologState::class, + \Laravel\Octane\Listeners\FlushStrCache::class, \Laravel\Octane\Listeners\FlushTranslatorCache::class, // First-Party Packages... diff --git a/src/Listeners/FlushStrCache.php b/src/Listeners/FlushStrCache.php new file mode 100644 index 000000000..caa232a47 --- /dev/null +++ b/src/Listeners/FlushStrCache.php @@ -0,0 +1,19 @@ +createOctaneContext([ + Request::create('/test-str-cache', 'GET'), + Request::create('/', 'GET'), + ]); + + $app['router']->middleware('web')->get('/', function () { + return 'Hello World'; + }); + + $app['router']->middleware('web')->get('/test-str-cache', function () { + return Str::snake('Taylor Otwell'); + }); + + $reflection = new ReflectionClass(Str::class); + $property = $reflection->getProperty('snakeCache'); + $property->setAccessible(true); + + $this->assertEmpty($property->getValue()); + + $worker->run(); + + $this->assertEmpty($property->getValue()); + } +}