Skip to content

Commit 137518d

Browse files
committed
add argument to prepend extension config
1 parent 4e944be commit 137518d

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add argument `$prepend` to `ContainerConfigurator::extension()` to prepend the configuration instead of appending it
8+
49
7.0
510
---
611

src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ public function __construct(ContainerBuilder $container, PhpFileLoader $loader,
4848
$this->env = $env;
4949
}
5050

51-
final public function extension(string $namespace, array $config): void
51+
final public function extension(string $namespace, array $config, bool $prepend = false): void
5252
{
53+
if ($prepend) {
54+
$this->container->prependExtensionConfig($namespace, static::processValue($config));
55+
56+
return;
57+
}
58+
5359
if (!$this->container->hasExtension($namespace)) {
5460
$extensions = array_filter(array_map(fn (ExtensionInterface $ext) => $ext->getAlias(), $this->container->getExtensions()));
5561
throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in "%s"). Looked for namespace "%s", found "%s".', $namespace, $this->file, $namespace, $extensions ? implode('", "', $extensions) : 'none'));

src/Symfony/Component/DependencyInjection/Tests/Extension/AbstractExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function prependExtension(ContainerConfigurator $container, ContainerBuil
6363
$container->extension('third', ['foo' => 'append']);
6464

6565
// prepend config
66-
$builder->prependExtensionConfig('third', ['foo' => 'prepend']);
66+
$container->extension('third', ['foo' => 'prepend'], true);
6767
}
6868
};
6969

src/Symfony/Component/HttpKernel/Tests/Fixtures/AcmeFooBundle/AcmeFooBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function configure(DefinitionConfigurator $definition): void
3131

3232
public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
3333
{
34-
$container->extension('loaded', ['bar' => 'baz']);
34+
$container->extension('loaded', ['bar' => 'baz'], true);
3535
}
3636

3737
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void

0 commit comments

Comments
 (0)