Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8130f22

Browse filesBrowse files
committed
bug #27472 [DI] Ignore missing tree root nodes on validate (ro0NL)
This PR was squashed before being merged into the 4.1 branch (closes #27472). Discussion ---------- [DI] Ignore missing tree root nodes on validate | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | technically yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #27450 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- b3cdfc6 [DI] Ignore missing tree root nodes on validate
2 parents 0ed3d0d + b3cdfc6 commit 8130f22
Copy full SHA for 8130f22

File tree

4 files changed

+58
-4
lines changed
Filter options

4 files changed

+58
-4
lines changed

‎src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Config\Definition\Builder;
1313

14+
use Symfony\Component\Config\Definition\Exception\TreeWithoutRootNodeException;
1415
use Symfony\Component\Config\Definition\NodeInterface;
1516

1617
/**
@@ -74,7 +75,7 @@ public function setPathSeparator(string $separator)
7475
private function assertTreeHasRootNode()
7576
{
7677
if (null === $this->root) {
77-
throw new \RuntimeException('The configuration tree has no root node.');
78+
throw new TreeWithoutRootNodeException('The configuration tree has no root node.');
7879
}
7980
}
8081
}
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Config\Definition\Exception;
13+
14+
/**
15+
* @author Roland Franssen <franssen.roland@gmail.com>
16+
*/
17+
class TreeWithoutRootNodeException extends \RuntimeException
18+
{
19+
}

‎src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\Config\Definition\BaseNode;
15+
use Symfony\Component\Config\Definition\Exception\TreeWithoutRootNodeException;
1516
use Symfony\Component\Config\Definition\Processor;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
@@ -75,7 +76,10 @@ public function process(ContainerBuilder $container)
7576
continue;
7677
}
7778

78-
$processor->processConfiguration($configuration, $config);
79+
try {
80+
$processor->processConfiguration($configuration, $config);
81+
} catch (TreeWithoutRootNodeException $e) {
82+
}
7983
}
8084
} finally {
8185
BaseNode::resetPlaceholders();

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php
+32-2Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1616
use Symfony\Component\Config\Definition\ConfigurationInterface;
17+
use Symfony\Component\Config\Definition\Exception\TreeWithoutRootNodeException;
1718
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
1819
use Symfony\Component\DependencyInjection\Compiler\RegisterEnvVarProcessorsPass;
1920
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
@@ -222,6 +223,17 @@ public function testEnvWithVariableNode(): void
222223
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
223224
}
224225

226+
public function testConfigurationWithoutRootNode(): void
227+
{
228+
$container = new ContainerBuilder();
229+
$container->registerExtension($ext = new EnvExtension(new EnvConfigurationWithoutRootNode()));
230+
$container->loadFromExtension('env_extension');
231+
232+
$this->doProcess($container);
233+
234+
$this->addToAssertionCount(1);
235+
}
236+
225237
private function doProcess(ContainerBuilder $container): void
226238
{
227239
(new MergeExtensionConfigurationPass())->process($container);
@@ -267,23 +279,41 @@ public function getConfigTreeBuilder()
267279
}
268280
}
269281

282+
class EnvConfigurationWithoutRootNode implements ConfigurationInterface
283+
{
284+
public function getConfigTreeBuilder()
285+
{
286+
return new TreeBuilder();
287+
}
288+
}
289+
270290
class EnvExtension extends Extension
271291
{
292+
private $configuration;
272293
private $config;
273294

295+
public function __construct(ConfigurationInterface $configuration = null)
296+
{
297+
$this->configuration = $configuration ?? new EnvConfiguration();
298+
}
299+
274300
public function getAlias()
275301
{
276302
return 'env_extension';
277303
}
278304

279305
public function getConfiguration(array $config, ContainerBuilder $container)
280306
{
281-
return new EnvConfiguration();
307+
return $this->configuration;
282308
}
283309

284310
public function load(array $configs, ContainerBuilder $container)
285311
{
286-
$this->config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
312+
try {
313+
$this->config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
314+
} catch (TreeWithoutRootNodeException $e) {
315+
$this->config = null;
316+
}
287317
}
288318

289319
public function getConfig()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.