8000 [DI] Ignore missing tree root nodes on validate by ro0NL · Pull Request #27472 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Ignore missing tree root nodes on validate #27472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
10000 Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Config\Definition\Builder;

use Symfony\Component\Config\Definition\Exception\TreeWithoutRootNodeException;
use Symfony\Component\Config\Definition\NodeInterface;

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ public function setPathSeparator(string $separator)
private function assertTreeHasRootNode()
{
if (null === $this->root) {
throw new \RuntimeException('The configuration tree has no root node.');
throw new TreeWithoutRootNodeException('The configuration tree has no root node.');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Config\Definition\Exception;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
*/
class TreeWithoutRootNodeException extends \RuntimeException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;

use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Exception\TreeWithoutRootNodeException;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;
Expand Down Expand Up @@ -77,7 +78,10 @@ public function process(ContainerBuilder $container)
continue;
}

$processor->processConfiguration($configuration, $config);
try {
$processor->processConfiguration($configuration, $config);
} catch (TreeWithoutRootNodeException $e) {
}
}
} finally {
BaseNode::resetPlaceholders();
Expand Down
98DE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Exception\TreeWithoutRootNodeException;
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
use Symfony\Component\DependencyInjection\Compiler\RegisterEnvVarProcessorsPass;
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
Expand Down Expand Up @@ -222,6 +223,17 @@ public function testEnvWithVariableNode(): void
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
}

public function testConfigurationWithoutRootNode(): void
{
$container = new ContainerBuilder();
$container->registerExtension($ext = new EnvExtension(new EnvConfigurationWithoutRootNode()));
$container->loadFromExtension('env_extension');

$this->doProcess($container);

$this->addToAssertionCount(1);
}

private function doProcess(ContainerBuilder $container): void
{
(new MergeExtensionConfigurationPass())->process($container);
Expand Down Expand Up @@ -267,23 +279,41 @@ public function getConfigTreeBuilder()
}
}

class EnvConfigurationWithoutRootNode implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
return new TreeBuilder();
}
}

class EnvExtension extends Extension
{
private $configuration;
private $config;

public function __construct(ConfigurationInterface $configuration = null)
{
$this->configuration = $configuration ?? new EnvConfiguration();
}

public function getAlias()
{
return 'env_extension';
}

public function getConfiguration(array $config, ContainerBuilder $container)
{
return new EnvConfiguration();
return $this->configuration;
}

public function load(array $configs, ContainerBuilder $container)
{
$this->config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
try {
$this->config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
} catch (TreeWithoutRootNodeException $e) {
$this->config = null;
}
}

public function getConfig()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them"
},
"conflict": {
"symfony/config": "<4.1",
"symfony/config": "<4.1.1",
"symfony/finder": "<3.4",
"symfony/proxy-manager-bridge": "<3.4",
"symfony/yaml": "<3.4"
Expand Down
0