Skip to content

Commit

Permalink
[HttpKernel] added check of default extension alias convention
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed Apr 26, 2011
1 parent 7dfe286 commit 97f66e9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -66,7 +66,24 @@ public function getContainerExtension()
{
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) {
Expand Down

6 comments on commit 97f66e9

@nicwortel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kriswallsmith why does Symfony enforce that the extension's alias matches the result of Container::underscore? We would like to to override this alias, but the LogicException prevents us from doing so. Which parts of Symfony rely on the alias being exactly the same as the underscored version of our bundle name?

I have discovered that I can work around the exception by overriding Bundle::getContainerExtension(), but I obviously want to be sure that this doesn't introduce any unexpected side-effects.

In my case, our bundle name (ODMediaFooBundle) results in the alias od_media_foo, and we would like to change that to odmedia_foo, removing the underscore between 'od' and 'media'.

@nicwortel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrobeson thanks. I was hoping that Kris would get the message since I tagged him. Are you sure that overriding Bundle::getContainerExtension() doesn't introduce unwanted side-effects?

@nicwortel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find it anywhere in the documentation, though... nor can I find a reason why the naming convention is being enforced in this way. But I'll just try it, and see if I'm getting any problems with it.

@nicwortel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Are you referring to this pull request?

@weaverryan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also personally have always wondered why we enforced this so rigidly :). Obviously, @nicwortel you have a workaround, but this also don't know the answer to the "why" here.

@wouterj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's find out why: #11684

Please sign in to comment.