From 97f66e93ac78a2f775c67ff38bb362b1e65da1d8 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 26 Apr 2011 07:16:31 -0700 Subject: [PATCH] [HttpKernel] added check of default extension alias convention --- .../Component/HttpKernel/Bundle/Bundle.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 546398525b..eb4285e755 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/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) {