-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Fixes memory leak on Translator implementation (#416)
* Fixes memory leak on translator keys * Apply fixes from StyleCI * Bumps framework dependency Co-authored-by: Taylor Otwell <taylorotwell@users.noreply.github.com>
- Loading branch information
1 parent
750a072
commit fbde6dd
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Laravel\Octane\Listeners; | ||
|
||
use Illuminate\Support\NamespacedItemResolver; | ||
|
||
class FlushTranslatorCache | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @param mixed $event | ||
* @return void | ||
*/ | ||
public function handle($event) | ||
{ | ||
if (! $event->sandbox->resolved('translator')) { | ||
return; | ||
} | ||
|
||
$translator = $event->sandbox->make('translator'); | ||
|
||
if ($translator instanceof NamespacedItemResolver) { | ||
$translator->flushParsedKeys(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Laravel\Octane\Listeners; | ||
|
||
use Illuminate\Http\Request; | ||
use Laravel\Octane\Tests\TestCase; | ||
use Mockery; | ||
|
||
class FlushTranslatorCacheTest extends TestCase | ||
{ | ||
/** @doesNotPerformAssertions */ | ||
public function test_parsed_keys_cache_is_flushed() | ||
{ | ||
[$app, $worker, $client] = $this->createOctaneContext([ | ||
Request::create('/test-translator', 'GET'), | ||
Request::create('/test-translator', 'GET'), | ||
]); | ||
|
||
$app['router']->middleware('web')->get('/test-cache', function () { | ||
Validator::make($data, [ | ||
'name' => 'string|max:50', | ||
])->validate(); | ||
}); | ||
|
||
$translator = $app['translator']; | ||
|
||
$app['translator'] = tap(Mockery::mock($translator), function ($translator) { | ||
$translator->shouldReceive('flushParsedKeys')->twice(); | ||
}); | ||
|
||
$worker->run(); | ||
} | ||
} |