Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the current App instance to FilesystemManager #458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"require": {
"php": "^8.0",
"laravel/framework": "^8.70",
"laravel/framework": "^8.77",
"laminas/laminas-diactoros": "^2.5",
"laravel/serializable-closure": "^1.0",
"symfony/psr-http-message-bridge": "^2.0"
Expand Down
1 change: 1 addition & 0 deletions src/Concerns/ProvidesDefaultConfigurationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function prepareApplicationForNextOperation(): array
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToBroadcastManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseSessionHandler::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToFilesystemManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToHttpKernel::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToMailManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class,
Expand Down
23 changes: 23 additions & 0 deletions src/Listeners/GiveNewApplicationInstanceToFilesystemManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Octane\Listeners;

class GiveNewApplicationInstanceToFilesystemManager
{
/**
* Handle the event.
*
* @param mixed $event
* @return void
*/
public function handle($event): void
{
if (! $event->sandbox->resolved('filesystem')) {
return;
}

with($event->sandbox->make('filesystem'), function ($manager) use ($event) {
$manager->setApplication($event->sandbox);
});
}
}
28 changes: 28 additions & 0 deletions tests/FilesystemManagerStateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Laravel\Octane\Tests;

use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use ReflectionProperty;

class FilesystemManagerStateTest extends TestCase
{
public function test_filesystem_manager_has_fresh_application_instance()
{
[$app, $worker, $client] = $this->createOctaneContext([
Request::create('/first', 'GET'),
Request::create('/first', 'GET'),
]);

$filesystemManagerApplication = new ReflectionProperty($app['filesystem'], 'app');

$app['router']->get('/first', function (Application $app) use ($filesystemManagerApplication) {
return spl_object_hash($filesystemManagerApplication->getValue($app['filesystem']));
});

$worker->run();

$this->assertNotEquals($client->responses[0]->original, $client->responses[1]->original);
}
}