Bladeren bron

[HttpKernel] added check of default extension alias convention

Kris Wallsmith 14 jaren geleden
bovenliggende
commit
97f66e93ac
1 gewijzigde bestanden met toevoegingen van 18 en 1 verwijderingen
  1. 18 1
      src/Symfony/Component/HttpKernel/Bundle/Bundle.php

+ 18 - 1
src/Symfony/Component/HttpKernel/Bundle/Bundle.php

@@ -66,7 +66,24 @@ abstract class Bundle extends ContainerAware implements BundleInterface
     {
         if (null === $this->extension) {
             $class = $this->getNamespace().'\\DependencyInjection\\'.str_replace('Bundle', 'Extension', $this->getName());
-            $this->extension = class_exists($class) ? new $class() : false;
+            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;
+            }
         }
 
         if ($this->extension) {