Commit 93e3f5bf authored by effulgentsia's avatar effulgentsia Committed by katbailey
Browse files

Issue #1711492: Improved override of Symfony's ContainerBuilder

parent 76892513
......@@ -8,28 +8,38 @@
namespace Drupal\Core\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder as BaseContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\Container;
/**
* Drupal's dependency injection container.
* Drupal's dependency injection container builder.
*
* @todo Submit upstream patches to Symfony to not require these overrides.
*/
class ContainerBuilder extends BaseContainerBuilder {
public function __construct() {
parent::__construct();
$this->compiler = new Compiler();
}
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) {
$this->compiler->addPass($pass, $type);
/**
* Overrides Symfony\Component\DependencyInjection\ContainerBuilder::addObjectResource().
*
* Drupal does not use Symfony's Config component, so we override
* addObjectResource() with an empty implementation to prevent errors during
* container compilation.
*/
public function addObjectResource($object) {
}
public function compile() {
$this->compiler->compile($this);
$this->parameterBag->resolve();
/**
* Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set().
*
* Drupal's container builder can be used at runtime after compilation, so we
* override Symfony's ContainerBuilder's restriction on setting services in a
* frozen builder.
*
* @todo Restrict this to synthetic services only. Ideally, the upstream
* ContainerBuilder class should be fixed to allow setting synthetic
* services in a frozen builder.
*/
public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
Container::set($id, $service, $scope);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment