Skip to content

Commit 97f66e9

Browse files
committed
[HttpKernel] added check of default extension alias convention
1 parent 7dfe286 commit 97f66e9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,24 @@ public function getContainerExtension()
6666
{
6767
if (null === $this->extension) {
6868
$class = $this->getNamespace().'\\DependencyInjection\\'.str_replace('Bundle', 'Extension', $this->getName());
69-
$this->extension = class_exists($class) ? new $class() : false;
69+
if (class_exists($class)) {
70+
$extension = new $class();
71+
72+
// check naming convention
73+
$expectedAlias = Container::underscore(str_replace('Bundle', '', $this->getName()));
74+
if ($expectedAlias != $extension->getAlias()) {
75+
throw new \LogicException(sprintf(
76+
'The extension alias for the default extension of a '.
77+
'bundle must be the underscored version of the '.
78+
'bundle name ("%s" vs "%s")',
79+
$expectedAlias, $extension->getAlias()
80+
));
81+
}
82+
83+
$this->extension = $extension;
84+
} else {
85+
$this->extension = false;
86+
}
7087
}
7188

7289
if ($this->extension) {

0 commit comments

Comments
 (0)