From 6cc241a1f59e9fcf3e2bd5ecf3a6c1bc9f56c0c4 Mon Sep 17 00:00:00 2001 From: Olivier Laviale Date: Mon, 30 Sep 2024 23:14:18 +0200 Subject: [PATCH] Add app.config.* parameters --- MIGRATION.md => CHANGELOG.md | 7 ++++++- docker-compose.yaml | 1 - src/ContainerFactory.php | 13 +++++++++++++ tests/src/IntegrationTest.php | 31 ++++++++++++++++++++++--------- 4 files changed, 41 insertions(+), 11 deletions(-) rename MIGRATION.md => CHANGELOG.md (89%) diff --git a/MIGRATION.md b/CHANGELOG.md similarity index 89% rename from MIGRATION.md rename to CHANGELOG.md index 3492811..23fd969 100644 --- a/MIGRATION.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# Migration +# CHANGELOG # v5.0 to v6.0 @@ -14,6 +14,7 @@ - The package uses the new config builder feature introduced by [ICanBoogie/Config][] v6.0. The configuration is now an instance of `Config` and no longer an array. + Before: ```php configs[ContainerConfig::FRAGMENT_FOR_CONTAINER][ContainerConfig::USE_CACHING]; ``` + After: ```php config_for_class(Config::class)->use_caching; ``` +## New features + +- `AppConfig` parameters are added as `app.config.*` parameters; for example `app.config.var`. [ICanBoogie/Config]: https://github.com/ICanBoogie/Config/ diff --git a/docker-compose.yaml b/docker-compose.yaml index bb66bbd..c61b622 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,4 @@ --- -version: "3.2" services: app82: build: diff --git a/src/ContainerFactory.php b/src/ContainerFactory.php index fdb5139..45d6b73 100644 --- a/src/ContainerFactory.php +++ b/src/ContainerFactory.php @@ -82,6 +82,7 @@ private function create_container_builder(): ContainerBuilder { $container = new ContainerBuilder(); + $this->apply_parameters($container); $this->apply_services($container); $this->apply_compiler_passes($container); $this->apply_extensions($container); @@ -89,6 +90,18 @@ private function create_container_builder(): ContainerBuilder return $container; } + private function apply_parameters(ContainerBuilder $container): void + { + $config = $this->app->config; + + $container->setParameter("app.config.var", $config->var); + $container->setParameter("app.config.var_cache", $config->var_cache); + $container->setParameter("app.config.var_cache_configs", $config->var_cache_configs); + $container->setParameter("app.config.var_files", $config->var_files); + $container->setParameter("app.config.var_lib", $config->var_lib); + $container->setParameter("app.config.var_tmp", $config->var_tmp); + } + private function apply_compiler_passes(ContainerBuilder $builder): void { foreach ($this->compiler_passes() as $compiler_pass) { diff --git a/tests/src/IntegrationTest.php b/tests/src/IntegrationTest.php index b4cdf7c..d357851 100644 --- a/tests/src/IntegrationTest.php +++ b/tests/src/IntegrationTest.php @@ -1,20 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\Binding\SymfonyDependencyInjection; use ICanBoogie\Autoconfig\Autoconfig; use ICanBoogie\ConfigProvider; use ICanBoogie\ServiceProvider; use ICanBoogie\Storage\Storage; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Test\ICanBoogie\Binding\SymfonyDependencyInjection\Acme\ServiceA; use Test\ICanBoogie\Binding\SymfonyDependencyInjection\Acme\ServiceB; @@ -61,4 +53,25 @@ public function test_compiler_pass_parameter(): void app()->container->getParameter('compiler_pass_parameter') ); } + + #[DataProvider("provide_app_config_parameter")] + public function test_app_config_parameter(string $param, mixed $expected): void + { + $actual = app()->container->getParameter($param); + + $this->assertEquals($expected, $actual); + } + + /** @phpstan-ignore-next-line */ + public static function provide_app_config_parameter(): array + { + return [ + [ "app.config.var", "var/" ], + [ "app.config.var_cache", "var/cache/" ], + [ "app.config.var_cache_configs", "var/cache/configs/" ], + [ "app.config.var_files", "var/files/" ], + [ "app.config.var_lib", "var/lib/" ], + [ "app.config.var_tmp", "var/tmp/" ], + ]; + } }