Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 1 addition & 37 deletions src/Config/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
class Setup
{
protected bool $hierarchical;

protected ?string $module;

protected ?string $pathPrefix;
Expand All @@ -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!';
}
Expand Down Expand Up @@ -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;
}
}
14 changes: 6 additions & 8 deletions src/Config/Traits/ConfigFileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 4 additions & 14 deletions tests/Unit/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -64,7 +64,7 @@ public function testModuleConfigTakesPrecedenceOverSharedConfig(): void

try {
$this->createFile($moduleConfig, "<?php\n\nreturn ['name' => '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 {
Expand All @@ -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'));
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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'));
Expand Down
56 changes: 17 additions & 39 deletions tests/Unit/Config/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Database/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Database/Factories/TableFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Migration/MigrationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Validation/Traits/GeneralRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading