Skip to content

Commit 272698b

Browse files
committed
Merge branch 'feature/cli-boot-fix' into develop
2 parents 5797cc2 + 67671b8 commit 272698b

3 files changed

Lines changed: 68 additions & 10 deletions

File tree

src/Application/Base.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,16 @@ protected function initSettings( ?ISettingSource $source ): void
717717

718718
try
719719
{
720-
$this->_settings = new SettingManager( $source );
720+
// If source is already a SettingManager, use it directly (avoids double-wrapping)
721+
// Otherwise wrap the raw source in a SettingManager (backward compatibility)
722+
if( $source instanceof SettingManager )
723+
{
724+
$this->_settings = $source;
725+
}
726+
else
727+
{
728+
$this->_settings = new SettingManager( $source );
729+
}
721730

722731
$basePath = $this->getSetting( 'system','base_path' ) ?? $defaultBasePath;
723732
$fallback = new Env( Data\Env::getInstance( "$basePath/.env" ) );

tests/Application/ApplicationTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,5 +534,62 @@ public function testInitSettingsUsesEnvVariable()
534534

535535
$this->assertNotNull($app->getSettingManager());
536536
}
537+
538+
public function testInitSettingsWithSettingManagerUsesItDirectly()
539+
{
540+
// Clear registry
541+
Registry::getInstance()->set(RegistryKeys::SETTINGS, null);
542+
543+
// Create a SettingManager with a raw source
544+
$rawSource = new Ini('examples/config/application.ini');
545+
$settingManager = new \Neuron\Data\Settings\SettingManager($rawSource);
546+
547+
// Pass the SettingManager to the app
548+
$app = new AppMock("2.0", $settingManager);
549+
550+
// The app should use the SettingManager directly (not wrap it again)
551+
$appSettings = $app->getSettingManager();
552+
$this->assertSame($settingManager, $appSettings);
553+
554+
// Verify we don't have double-wrapping by checking the internal source
555+
// If double-wrapped, getSource() would return a SettingManager instead of the raw Ini
556+
$this->assertInstanceOf(Ini::class, $appSettings->getSource());
557+
$this->assertNotInstanceOf(\Neuron\Data\Settings\SettingManager::class, $appSettings->getSource());
558+
}
559+
560+
public function testInitSettingsWithRawSourceWrapsIt()
561+
{
562+
// Clear registry
563+
Registry::getInstance()->set(RegistryKeys::SETTINGS, null);
564+
565+
// Pass a raw source (not a SettingManager)
566+
$rawSource = new Ini('examples/config/application.ini');
567+
$app = new AppMock("2.0", $rawSource);
568+
569+
// The app should wrap it in a SettingManager
570+
$appSettings = $app->getSettingManager();
571+
$this->assertInstanceOf(\Neuron\Data\Settings\SettingManager::class, $appSettings);
572+
573+
// Verify the raw source is wrapped
574+
$this->assertInstanceOf(Ini::class, $appSettings->getSource());
575+
}
576+
577+
public function testInitSettingsSetsEnvFallbackWhenNoneProvided()
578+
{
579+
// Clear registry
580+
Registry::getInstance()->set(RegistryKeys::SETTINGS, null);
581+
582+
// Create a SettingManager without a fallback
583+
$rawSource = new Ini('examples/config/application.ini');
584+
$settingManager = new \Neuron\Data\Settings\SettingManager($rawSource);
585+
586+
// Pass the SettingManager to the app
587+
$app = new AppMock("2.0", $settingManager);
588+
589+
// The app should set a fallback (env variables)
590+
$appSettings = $app->getSettingManager();
591+
$this->assertNotNull($appSettings->getFallback());
592+
$this->assertInstanceOf(\Neuron\Data\Settings\Source\Env::class, $appSettings->getFallback());
593+
}
537594
}
538595

versionlog.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
## 0.8.16
2+
* Fix to support setting managers or sources correctly without incurring a manager that contains a manager.
23

34
## 0.8.15 2026-01-13
4-
55
## 0.8.14 2026-01-12
6-
76
## 0.8.13 2026-01-06
87

98
## 0.8.12 2026-01-01
109
* Added psr-11 container support.
1110

1211
## 0.8.11 2025-12-26
13-
1412
## 0.8.10 2025-11-28
1513

1614
## 0.8.9 2025-11-27
@@ -25,30 +23,24 @@
2523
* Renamed config.yaml to neuron.yaml
2624

2725
## 0.8.5 2025-11-11
28-
2926
## 0.8.4 2025-11-10
30-
3127
## 0.8.3 2025-11-10
3228
* Improved error handling.
3329

3430
## 0.8.2 2025-11-08
35-
3631
## 0.8.1 2025-11-06
3732

3833
* Added getSettingManager() method to provide access to SettingManager instance
3934

4035
## 0.7.1 2025-11-04
41-
4236
## 0.7.0 2025-08-14
4337
* Refactored get/set setting methods.
4438

4539
## 0.6.33 2025-05-23
4640
* Added the Crashed state.
4741

4842
## 0.6.32 2025-05-21
49-
5043
## 0.6.31
51-
5244
## 0.6.30 2025-02-06
5345
* Transitioned from core package to application.
5446

0 commit comments

Comments
 (0)