diff --git a/CHANGELOG.md b/CHANGELOG.md index 29fa38bd..0c395b44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on Keep a Changelog. - `vaibhavpandeyvpz/phemail`, which `MailTrap` uses to read saved emails, is updated to 2.0. Its API is unchanged, and `MailTrap` behaves as before (#687) - The test suite runs on PHPUnit `^11.5` (a development dependency). Its tests use attributes such as `#[DataProvider]` instead of doc-comment markers, which PHPUnit 12 no longer reads (#687) - **BREAKING:** The `single` and `daily` log adapters write the context of a log call after the message, as one line of JSON, for example `[2026-11-23 14:02:11] Info: Order paid {"order":1042}`; they ignored it, so a failed cron task lost its `exception`, `file` and `line`. A `trace` that is text stays on its own lines, an exception in the context is written as its class, message, file and line, and a context value that cannot be converted never makes the log call fail. A line without a context is unchanged. A tool that parses log lines must allow the JSON at the end, and passwords or tokens passed in the context now reach the log file. The message stays `string|Stringable`, as PSR-3 defines: `logger()->info([...])` throws a `TypeError`, so put structured data in the context, and a custom adapter that uses `LoggerTrait` must pass `formatMessage()` a string (#613) +- **BREAKING:** The hierarchy flag of `Quantum\Config\Setup`, deprecated in 3.1.2, is removed: the `$hierarchical` constructor argument, `setHierarchy()` and `getHierarchy()`. A module's config file that does not exist always falls back to `shared/config`. The constructor takes `($pathPrefix, $fileName, $module, $exceptionMessage)`, so the module and the exception message move up one position: `new Setup('config', 'app', true, 'Admin')` must become `new Setup('config', 'app', module: 'Admin')`. In a file that declares `strict_types`, the old call fails with a `TypeError`. Without it, PHP turns `true` into the module `1` and `false` into no module, which means the current request's module, and the module name becomes the exception message, so the config is read from `shared` or from the wrong module without an error. Calls that pass only the first two arguments, or the module as a named argument, are unaffected (#619) ### Fixed - The storage adapters no longer raise PHP warnings where they return `false`: `LocalFileSystemAdapter::listDirectory()` returns `false` for a folder that does not exist without calling `scandir()`, `DropboxFileSystemAdapter::put()` returns `false` when the response has no `size`, and `DropboxFileSystemAdapter::isFile()` and `GoogleDriveFileSystemAdapter::isFile()` return `false` when the metadata lacks `.tag`, `kind` or `mimeType` (#687) diff --git a/src/Config/Setup.php b/src/Config/Setup.php index b9de105c..88dfdd17 100644 --- a/src/Config/Setup.php +++ b/src/Config/Setup.php @@ -19,8 +19,6 @@ */ class Setup { - protected bool $hierarchical; - protected ?string $module; protected ?string $pathPrefix; @@ -30,22 +28,12 @@ class Setup protected string $exceptionMessage; /** - * @param bool|null $hierarchical Deprecated, will be removed in 3.2.0 * @throws DiException|ReflectionException */ - public function __construct(?string $pathPrefix = null, ?string $fileName = null, ?bool $hierarchical = null, ?string $module = null, ?string $exceptionMessage = null) + public function __construct(?string $pathPrefix = null, ?string $fileName = null, ?string $module = null, ?string $exceptionMessage = null) { - if ($hierarchical !== null) { - trigger_error( - 'The $hierarchical argument of ' . __METHOD__ . '() is deprecated and will be removed in 3.2.0; ' - . 'the fallback to the shared config will always be on. To pass a module, use the module: named argument.', - E_USER_DEPRECATED - ); - } - $this->pathPrefix = $pathPrefix; $this->fileName = $fileName; - $this->hierarchical = $hierarchical ?? true; $this->module = $module ?: request()->getCurrentModule(); $this->exceptionMessage = $exceptionMessage ?: 'File `' . $pathPrefix . DS . $fileName . '` not found!'; } @@ -117,28 +105,4 @@ public function getExceptionMessage(): string { return $this->exceptionMessage; } - - /** - * Set the hierarchy - * @deprecated Will be removed in 3.2.0; the fallback to the shared config will always be on - */ - public function setHierarchy(bool $hierarchy): Setup - { - trigger_error( - __METHOD__ . '() is deprecated and will be removed in 3.2.0; the fallback to the shared config will always be on.', - E_USER_DEPRECATED - ); - - $this->hierarchical = $hierarchy; - return $this; - } - - /** - * Gets the hierarchy - * @deprecated Will be removed in 3.2.0; the fallback to the shared config will always be on - */ - public function getHierarchy(): bool - { - return $this->hierarchical; - } } diff --git a/src/Config/Traits/ConfigFileTrait.php b/src/Config/Traits/ConfigFileTrait.php index 4bf2770f..73aae5c2 100644 --- a/src/Config/Traits/ConfigFileTrait.php +++ b/src/Config/Traits/ConfigFileTrait.php @@ -92,14 +92,12 @@ private function resolveFilePath(Setup $setup): ?string return $filePath; } - if ($setup->getHierarchy()) { - $filePath = $baseDir . DS . 'shared' . DS - . strtolower($setup->getPathPrefix() ?? '') . DS - . $setup->getFilename() . '.php'; - - if (file_exists($filePath)) { - return $filePath; - } + $filePath = $baseDir . DS . 'shared' . DS + . strtolower($setup->getPathPrefix() ?? '') . DS + . $setup->getFilename() . '.php'; + + if (file_exists($filePath)) { + return $filePath; } return null; diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php index 80368c00..463e3260 100644 --- a/tests/Unit/Config/ConfigTest.php +++ b/tests/Unit/Config/ConfigTest.php @@ -49,7 +49,7 @@ public function testConfigImport(): void public function testImportLoadsModuleConfig(): void { - $this->config->import(new Setup('config', 'dependencies', true, 'Test')); + $this->config->import(new Setup('config', 'dependencies', module: 'Test')); $this->assertSame( PostTransformer::class, @@ -64,7 +64,7 @@ public function testModuleConfigTakesPrecedenceOverSharedConfig(): void try { $this->createFile($moduleConfig, " 'Module app'];\n"); - $this->config->import(new Setup('config', 'app', true, 'Test')); + $this->config->import(new Setup('config', 'app', module: 'Test')); $this->assertSame('Module app', $this->config->get('app.name')); } finally { @@ -74,7 +74,7 @@ public function testModuleConfigTakesPrecedenceOverSharedConfig(): void public function testImportFallsBackToSharedConfig(): void { - $this->config->import(new Setup('config', 'app', true, 'Test')); + $this->config->import(new Setup('config', 'app', module: 'Test')); $this->assertSame('Quantum PHP Framework', $this->config->get('app.name')); } @@ -99,7 +99,7 @@ public function testNonModuleConfigIsResolvedFromApplicationBase(): void try { chdir($workingDirectory); - $this->config->import(new Setup('config', $filename, false)); + $this->config->import(new Setup('config', $filename)); $this->assertSame('application', $this->config->get($filename . '.source')); } finally { @@ -145,16 +145,6 @@ public function testImportIfExistsPreservesCollision(): void $this->config->importIfExists(new Setup('config', 'app')); } - public function testImportDoesNotFallBackWhenHierarchyIsDisabled(): void - { - try { - $this->config->import(new Setup('config', 'app', false, 'Test')); - $this->fail('Expected a missing config exception'); - } catch (ConfigException $exception) { - $this->assertFalse($this->config->has('app')); - } - } - public function testLoadDoesNotReplacePreviouslyLoadedConfig(): void { $this->config->load(new Setup('config', 'app')); diff --git a/tests/Unit/Config/SetupTest.php b/tests/Unit/Config/SetupTest.php index e5e4add7..34ffb529 100644 --- a/tests/Unit/Config/SetupTest.php +++ b/tests/Unit/Config/SetupTest.php @@ -31,8 +31,6 @@ public function testSetupConstructor(): void $this->assertEquals('database', $setup->getFilename()); - $this->assertEquals(true, $setup->getHierarchy()); - $this->assertEquals('File `' . $setup->getPathPrefix() . DS . $setup->getFilename() . '` not found!', $setup->getExceptionMessage()); } @@ -45,7 +43,7 @@ public function testSetupUsesCurrentRequestModuleWhenModuleIsOmitted(): void request()->setMatchedRoute(null); $this->assertSame('Test', $setup->getModule()); - $this->assertSame('Meme', (new Setup('config', 'dependencies', true, 'Meme'))->getModule()); + $this->assertSame('Meme', (new Setup('config', 'dependencies', module: 'Meme'))->getModule()); } public function testDefaultExceptionMessageIsCapturedAtConstruction(): void @@ -71,13 +69,6 @@ public function testSetGetFilename(): void $this->assertEquals('users', $this->setup->getFilename()); } - public function testSetGetHierarchy(): void - { - $this->setup->setHierarchy(true); - - $this->assertTrue($this->setup->getHierarchy()); - } - public function testSetupRaisesNoDeprecationByDefault(): void { $messages = $this->collectDeprecations(function (): void { @@ -88,52 +79,39 @@ public function testSetupRaisesNoDeprecationByDefault(): void $this->assertSame([], $messages); } - public function testSetupRaisesDeprecationWhenHierarchicalArgumentIsPassed(): void + public function testSetGetModule(): void { - $messages = $this->collectDeprecations(function (): void { - new Setup('config', 'app', false); - }); + $this->setup->setModule('admin'); - $this->assertCount(1, $messages); - $this->assertStringContainsString('$hierarchical argument', $messages[0]); - $this->assertStringContainsString('3.2.0', $messages[0]); + $this->assertEquals('admin', $this->setup->getModule()); } - public function testSetupKeepsHierarchicalValueWhenArgumentIsPassed(): void + public function testSetGetExceptionMessage(): void { - $setup = null; - - $this->collectDeprecations(function () use (&$setup): void { - $setup = new Setup('config', 'app', false); - }); + $this->setup->setExceptionMessage('Action not allowed'); - $this->assertFalse($setup->getHierarchy()); + $this->assertEquals('Action not allowed', $this->setup->getExceptionMessage()); } - public function testSetHierarchyRaisesDeprecation(): void + public function testThirdArgumentIsTheModule(): void { - $messages = $this->collectDeprecations(function (): void { - $this->setup->setHierarchy(false); - }); + $setup = new Setup('config', 'app', 'Blog'); - $this->assertCount(1, $messages); - $this->assertStringContainsString('setHierarchy()', $messages[0]); - $this->assertStringContainsString('3.2.0', $messages[0]); - $this->assertFalse($this->setup->getHierarchy()); + $this->assertSame('Blog', $setup->getModule()); } - public function testSetGetModule(): void + public function testFourthArgumentIsTheExceptionMessage(): void { - $this->setup->setModule('admin'); + $setup = new Setup('config', 'app', 'Blog', 'App config is missing'); - $this->assertEquals('admin', $this->setup->getModule()); + $this->assertSame('Blog', $setup->getModule()); + $this->assertSame('App config is missing', $setup->getExceptionMessage()); } - public function testSetGetExceptionMessage(): void + public function testHierarchyMethodsAreRemoved(): void { - $this->setup->setExceptionMessage('Action not allowed'); - - $this->assertEquals('Action not allowed', $this->setup->getExceptionMessage()); + $this->assertFalse(method_exists(Setup::class, 'setHierarchy')); + $this->assertFalse(method_exists(Setup::class, 'getHierarchy')); } /** diff --git a/tests/Unit/Database/DatabaseTest.php b/tests/Unit/Database/DatabaseTest.php index 1c74091b..ac2ff8d8 100644 --- a/tests/Unit/Database/DatabaseTest.php +++ b/tests/Unit/Database/DatabaseTest.php @@ -15,7 +15,7 @@ public function setUp(): void parent::setUp(); if (!config()->has('database')) { - config()->import(new Setup('config', 'database', true)); + config()->import(new Setup('config', 'database')); } config()->set('database.default', 'sqlite'); diff --git a/tests/Unit/Database/Factories/TableFactoryTest.php b/tests/Unit/Database/Factories/TableFactoryTest.php index 0bed6ce7..88766ff8 100644 --- a/tests/Unit/Database/Factories/TableFactoryTest.php +++ b/tests/Unit/Database/Factories/TableFactoryTest.php @@ -20,7 +20,7 @@ public function setUp(): void parent::setUp(); if (!config()->has('database')) { - config()->import(new Setup('config', 'database', true)); + config()->import(new Setup('config', 'database')); } config()->set('database.default', 'sqlite'); diff --git a/tests/Unit/Migration/MigrationManagerTest.php b/tests/Unit/Migration/MigrationManagerTest.php index 48c9e343..a1ff9ab3 100644 --- a/tests/Unit/Migration/MigrationManagerTest.php +++ b/tests/Unit/Migration/MigrationManagerTest.php @@ -23,7 +23,7 @@ public function setUp(): void parent::setUp(); if (!config()->has('database')) { - config()->import(new Setup('config', 'database', true)); + config()->import(new Setup('config', 'database')); } config()->set('database.default', 'sqlite'); diff --git a/tests/Unit/Validation/Traits/GeneralRuleTest.php b/tests/Unit/Validation/Traits/GeneralRuleTest.php index b31f69bb..347d9735 100644 --- a/tests/Unit/Validation/Traits/GeneralRuleTest.php +++ b/tests/Unit/Validation/Traits/GeneralRuleTest.php @@ -20,7 +20,7 @@ public function setUp(): void $this->validator = new Validator(); if (!config()->has('database')) { - config()->import(new Setup('config', 'database', true)); + config()->import(new Setup('config', 'database')); } config()->set('database.default', 'sqlite');