Skip to content

Commit

Permalink
Add app.config.* parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Oct 20, 2024
1 parent 9715126 commit 29a0a32
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
7 changes: 6 additions & 1 deletion MIGRATION.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Migration
# CHANGELOG

# v5.0 to v6.0

Expand All @@ -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
<?php

Expand All @@ -26,6 +27,7 @@
$app->configs[ContainerConfig::FRAGMENT_FOR_CONTAINER][ContainerConfig::USE_CACHING];
```

After:
```php
<?php

Expand All @@ -39,6 +41,9 @@
$app->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/
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
version: "3.2"
services:
app82:
build:
Expand Down
13 changes: 13 additions & 0 deletions src/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,26 @@ 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);

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) {
Expand Down
4 changes: 4 additions & 0 deletions tests/app/all/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
parameters:

test.cache_dir: "%app.config.var_cache%test/"

services:

service_a:
Expand Down
32 changes: 23 additions & 9 deletions tests/src/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* 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;
Expand Down Expand Up @@ -61,4 +53,26 @@ 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/" ],
[ "test.cache_dir", "var/cache/test/" ],
];
}
}

0 comments on commit 29a0a32

Please sign in to comment.