10000 merged branch drak/kernel_dicb (PR #3909) · kimhemsoe/symfony@d87a197 · GitHub
[go: up one dir, main page]

Skip to content

Commit d87a197

Browse files
committed
merged branch drak/kernel_dicb (PR symfony#3909)
Commits ------- 82bbf3b [HttpKernel] Allow override of ContainerBuilder instance used to build container Discussion ---------- [HttpKernel] Allow override of ContainerBuilder class in Kernel Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - The ContainerBuilder class is hard coded into the `buildContainer()` method and is therefor not extensible. --------------------------------------------------------------------------- by fabpot at 2012-04-13T04:54:28Z I would definitely prefer a `getContainerBuilder()` that returns a container builder. But why would you want to do that? --------------------------------------------------------------------------- by drak at 2012-04-13T05:12:13Z @fabpot - The use case is to override the behaviour of the compilation that is performed by the kernel on the container. There is no way to override the compile() method called on the builder because the class is created hard in `Kernel::buildContainer()`. This was the simplest way to change it without other cascading changes. If we had a method which returned a container builder instance, would it just be something that creates a container builder, or acts as a getter on a property? The reason I ask is there is no real need to have a container builder persisting in a property, so a method that just returns a `new ContainerBuilder()` would also work but then we have to deal with the constructor as there is no way to set a ParameterBag on a container and `Kernel::buildContainer()` needs that. Basically, my reasoning is that since this particular container is just a throwaway, it seems ok to control the class name that was used to create the throwaway builder. So are you suggesting doing this instead? protected function getContainerBuilder() { return new ContainerBuilder(new ParameterBag($this->getKernelParameters())); } --------------------------------------------------------------------------- by fabpot at 2012-04-13T05:22:20Z Yes this was my suggestion. But are you sure you cannot solve your problems with compiler passes? --------------------------------------------------------------------------- by drak at 2012-04-13T05:38:29Z @fabpot, yes, this particular issue can't be solved by compiler passes. I'll adapt the PR. --------------------------------------------------------------------------- by drak at 2012-04-13T05:46:03Z @fabpot, amended as per your suggestion.
2 parents 70df8d3 + 82bbf3b commit d87a197

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ protected function buildContainer()
640640
}
641641
}
642642

643-
$container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
643+
$container = $this->getContainerBuilder();
644644
$extensions = array();
645645
foreach ($this->bundles as $bundle) {
646646
if ($extension = $bundle->getContainerExtension()) {
@@ -671,6 +671,16 @@ protected function buildContainer()
671671
return $container;
672672
}
673673

674+
/**
675+
* Gets a new ContainerBuilder instance used to build the service container.
676+
*
677+
* @return ContainerBuilder
678+
*/
679+
protected function getContainerBuilder()
680+
{
681+
return new ContainerBuilder(new ParameterBag($this 51C4 ->getKernelParameters()));
682+
}
683+
674684
/**
675685
* Dumps the service container to PHP code in the cache.
676686
*

0 commit comments

Comments
 (0)
0