diff --git a/src/Concerns/ProvidesDefaultConfigurationOptions.php b/src/Concerns/ProvidesDefaultConfigurationOptions.php index ee5b2db0c..7f9319724 100644 --- a/src/Concerns/ProvidesDefaultConfigurationOptions.php +++ b/src/Concerns/ProvidesDefaultConfigurationOptions.php @@ -28,6 +28,7 @@ public static function prepareApplicationForNextOperation(): array { return [ \Laravel\Octane\Listeners\CreateConfigurationSandbox::class, + \Laravel\Octane\Listeners\CreateUrlGeneratorSandbox::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToAuthorizationGate::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToBroadcastManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseManager::class, diff --git a/src/Listeners/CreateUrlGeneratorSandbox.php b/src/Listeners/CreateUrlGeneratorSandbox.php new file mode 100644 index 000000000..88cc0ac1c --- /dev/null +++ b/src/Listeners/CreateUrlGeneratorSandbox.php @@ -0,0 +1,16 @@ +sandbox->instance('url', clone $event->sandbox['url']); + } +} diff --git a/src/OctaneServiceProvider.php b/src/OctaneServiceProvider.php index 4785822fe..92cae6aad 100644 --- a/src/OctaneServiceProvider.php +++ b/src/OctaneServiceProvider.php @@ -123,6 +123,7 @@ protected function bindListeners() { $this->app->singleton(Listeners\CollectGarbage::class); $this->app->singleton(Listeners\CreateConfigurationSandbox::class); + $this->app->singleton(Listeners\CreateUrlGeneratorSandbox::class); $this->app->singleton(Listeners\DisconnectFromDatabases::class); $this->app->singleton(Listeners\EnforceRequestScheme::class); $this->app->singleton(Listeners\EnsureRequestServerPortMatchesScheme::class); diff --git a/tests/UrlGeneratorSandboxTest.php b/tests/UrlGeneratorSandboxTest.php new file mode 100644 index 000000000..0827fd499 --- /dev/null +++ b/tests/UrlGeneratorSandboxTest.php @@ -0,0 +1,49 @@ +createOctaneContext([ + Request::create('/first', 'GET'), + Request::create('/second', 'GET'), + ]); + + $app['url']->defaults(['param' => 'original']); + $app['url']->forceRootUrl('http://original'); + + $app['router']->get('/first', function (Application $app) { + $app['url']->defaults(['param' => 'changed']); + $app['url']->forceRootUrl('http://changed'); + + return [ + 'default' => $app['url']->getDefaultParameters(), + 'url' => $app['url']->to('/'), + ]; + }); + + $app['router']->get('/second', function (Application $app) { + return [ + 'default' => $app['url']->getDefaultParameters(), + 'url' => $app['url']->to('/'), + ]; + }); + + $worker->run(); + + $this->assertEquals([ + 'default' => ['param' => 'changed'], + 'url' => 'http://changed', + ], $client->responses[0]->getData(true)); + + $this->assertEquals([ + 'default' => ['param' => 'original'], + 'url' => 'http://original', + ], $client->responses[1]->getData(true)); + } +}