From 143f39fad660b64b49d134f530832c168ff64fb0 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 1 Oct 2026 16:04:14 +0000 Subject: [PATCH] refactor(foundation): key:generate and config:publish follow configPath() (task 4.5) The last two fork paths built from app/config follow the configuration directory instead: - key:generate replaces the key in configPath('app.php'). Its --env variant wrote app/config/{env}/app.php, a folder the configuration no longer cascades from, so it goes. - The config publisher publishes package configuration under configPath(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo --- .../Foundation/Console/KeyGenerateCommand.php | 4 +- .../Providers/PublisherServiceProvider.php | 2 +- .../FoundationConfigurationPathTest.php | 69 +++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 tests/Foundation/FoundationConfigurationPathTest.php diff --git a/src/Illuminate/Foundation/Console/KeyGenerateCommand.php b/src/Illuminate/Foundation/Console/KeyGenerateCommand.php index 8c749bf7..f89597c8 100755 --- a/src/Illuminate/Foundation/Console/KeyGenerateCommand.php +++ b/src/Illuminate/Foundation/Console/KeyGenerateCommand.php @@ -64,9 +64,7 @@ public function handle() */ protected function getKeyFile() { - $env = $this->option('env') ? $this->option('env').'/' : ''; - - $contents = $this->files->get($path = $this->laravel['path']."/config/{$env}app.php"); + $contents = $this->files->get($path = $this->laravel->configPath('app.php')); return array($path, $contents); } diff --git a/src/Illuminate/Foundation/Providers/PublisherServiceProvider.php b/src/Illuminate/Foundation/Providers/PublisherServiceProvider.php index 085b83a9..25cd048c 100755 --- a/src/Illuminate/Foundation/Providers/PublisherServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/PublisherServiceProvider.php @@ -88,7 +88,7 @@ protected function registerConfigPublisher() $this->app->singleton('config.publisher', function($app) { - $path = $app['path'].'/config'; + $path = $app->configPath(); // Once we have created the configuration publisher, we will set the default // package path on the object so that it knows where to find the packages diff --git a/tests/Foundation/FoundationConfigurationPathTest.php b/tests/Foundation/FoundationConfigurationPathTest.php new file mode 100644 index 00000000..7a6252a0 --- /dev/null +++ b/tests/Foundation/FoundationConfigurationPathTest.php @@ -0,0 +1,69 @@ +base = sys_get_temp_dir().'/fork-config-path-'.uniqid(); + mkdir($this->base.'/settings', 0777, true); + } + + protected function tearDown(): void + { + $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->base, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST); + foreach ($files as $file) $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname()); + rmdir($this->base); + } + + #[Test] + public function keyGenerateReplacesTheKeyInTheConfiguredAppFile() + { + $old = str_repeat('o', 32); + file_put_contents($this->base.'/settings/app.php', " '{$old}', 'cipher' => 'AES-256-CBC');"); + $app = $this->application(); + $app->instance('config', new Repository(array('app' => array('key' => $old)))); + + $command = new KeyGenerateCommand(new Filesystem); + $command->setLaravel($app); + $status = $command->run(new ArrayInput(array()), $output = new BufferedOutput); + + $key = $app['config']['app.key']; + $this->assertSame(0, $status); + $this->assertSame(32, strlen($key)); + $this->assertNotSame($old, $key); + $this->assertSame(array('key' => $key, 'cipher' => 'AES-256-CBC'), require $this->base.'/settings/app.php'); + $this->assertStringContainsString("Application key [{$key}] set successfully.", $output->fetch()); + } + + #[Test] + public function configPublishPublishesUnderTheConfiguredPath() + { + $app = $this->application(); + $app->instance('files', new Filesystem); + (new PublisherServiceProvider($app))->register(); + + $this->assertSame($this->base.'/settings/packages/foo/bar', $app['config.publisher']->getDestinationPath('foo/bar')); + } + + private function application(): Application + { + $app = new Application; + $app->setBasePath($this->base); + $app->useConfigPath($this->base.'/settings'); + $app['env'] = 'testing'; + + return $app; + } +}