|
@@ -27,6 +27,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface
|
|
|
{
|
|
|
protected $name;
|
|
|
protected $reflected;
|
|
|
+ protected $extension;
|
|
|
|
|
|
/**
|
|
|
* Boots the Bundle.
|
|
@@ -47,13 +48,6 @@ abstract class Bundle extends ContainerAware implements BundleInterface
|
|
|
*
|
|
|
* It is only ever called once when the cache is empty.
|
|
|
*
|
|
|
- * The default implementation automatically registers a DIC extension
|
|
|
- * if its name is the same as the bundle name after replacing the
|
|
|
- * Bundle suffix by Extension (DependencyInjection\SensioBlogExtension
|
|
|
- * for a SensioBlogBundle for instance). In such a case, the alias
|
|
|
- * is forced to be the underscore version of the bundle name
|
|
|
- * (sensio_blog for a SensioBlogBundle for instance).
|
|
|
- *
|
|
|
* This method can be overridden to register compilation passes,
|
|
|
* other extensions, ...
|
|
|
*
|
|
@@ -61,15 +55,39 @@ abstract class Bundle extends ContainerAware implements BundleInterface
|
|
|
*/
|
|
|
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()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the bundle's container extension.
|
|
|
+ *
|
|
|
+ * @return ExtensionInterface|null The container extension
|
|
|
+ */
|
|
|
+ public function getContainerExtension()
|
|
|
+ {
|
|
|
+ if (null === $this->extension) {
|
|
|
+ $class = $this->getNamespace().'\\DependencyInjection\\'.str_replace('Bundle', 'Extension', $this->getName());
|
|
|
+ if (class_exists($class)) {
|
|
|
+ $extension = new $class();
|
|
|
+
|
|
|
+ // check naming convention
|
|
|
+ $expectedAlias = Container::underscore(str_replace('Bundle', '', $this->getName()));
|
|
|
+ if ($expectedAlias != $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")',
|
|
|
+ $expectedAlias, $extension->getAlias()
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->extension = $extension;
|
|
|
+ } else {
|
|
|
+ $this->extension = false;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- $container->registerExtension($extension);
|
|
|
+ if ($this->extension) {
|
|
|
+ return $this->extension;
|
|
|
}
|
|
|
}
|
|
|
|