|
@@ -223,10 +223,12 @@ class ContainerAware implements ContainerAwareInterface
|
|
|
}
|
|
|
namespace Symfony\Component\HttpKernel\Bundle
|
|
|
{
|
|
|
+use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
interface BundleInterface
|
|
|
{
|
|
|
function boot();
|
|
|
function shutdown();
|
|
|
+ public function build(ContainerBuilder $container);
|
|
|
function getParent();
|
|
|
function getName();
|
|
|
function getNamespace();
|
|
@@ -237,6 +239,7 @@ namespace Symfony\Component\HttpKernel\Bundle
|
|
|
{
|
|
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
+use Symfony\Component\DependencyInjection\Container;
|
|
|
use Symfony\Component\Console\Application;
|
|
|
use Symfony\Component\Finder\Finder;
|
|
|
abstract class Bundle extends ContainerAware implements BundleInterface
|
|
@@ -249,6 +252,18 @@ abstract class Bundle extends ContainerAware implements BundleInterface
|
|
|
public function shutdown()
|
|
|
{
|
|
|
}
|
|
|
+ public function build(ContainerBuilder $container)
|
|
|
+ {
|
|
|
+ $class = $this->getNamespace().'\\DependencyInjection\\'.str_replace('Bundle', 'Extension', $this->getName());
|
|
|
+ if (class_exists($class)) {
|
|
|
+ $extension = new $class();
|
|
|
+ $alias = Container::underscore(str_replace('Bundle', '', $this->getName()));
|
|
|
+ if ($alias !== $extension->getAlias()) {
|
|
|
+ throw new \LogicException(sprintf('The extension alias for the default extension of a bundle must be the underscored version of the bundle name ("%s" vs "%s")', $alias, $extension->getAlias()));
|
|
|
+ }
|
|
|
+ $container->registerExtension($extension);
|
|
|
+ }
|
|
|
+ }
|
|
|
public function getNamespace()
|
|
|
{
|
|
|
if (null === $this->reflected) {
|
|
@@ -276,19 +291,6 @@ abstract class Bundle extends ContainerAware implements BundleInterface
|
|
|
$pos = strrpos($name, '\\');
|
|
|
return $this->name = false === $pos ? $name : substr($name, $pos + 1);
|
|
|
}
|
|
|
- public function registerExtensions(ContainerBuilder $container)
|
|
|
- {
|
|
|
- if (!$dir = realpath($this->getPath().'/DependencyInjection')) {
|
|
|
- return;
|
|
|
- }
|
|
|
- $finder = new Finder();
|
|
|
- $finder->files()->name('*Extension.php')->in($dir);
|
|
|
- $prefix = $this->getNamespace().'\\DependencyInjection';
|
|
|
- foreach ($finder as $file) {
|
|
|
- $class = $prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.$file->getBasename('.php');
|
|
|
- $container->registerExtension(new $class());
|
|
|
- }
|
|
|
- }
|
|
|
public function registerCommands(Application $application)
|
|
|
{
|
|
|
if (!$dir = realpath($this->getPath().'/Command')) {
|
|
@@ -727,7 +729,7 @@ abstract class Kernel implements KernelInterface
|
|
|
$parameterBag = new ParameterBag($this->getKernelParameters());
|
|
|
$container = new ContainerBuilder($parameterBag);
|
|
|
foreach ($this->bundles as $bundle) {
|
|
|
- $bundle->registerExtensions($container);
|
|
|
+ $bundle->build($container);
|
|
|
if ($this->debug) {
|
|
|
$container->addObjectResource($bundle);
|
|
|
}
|