Skip to content

Commit 697ac87

Browse files
committed
[HttpKernel] Add entry point to more easily create/configure the DI extension
1 parent 542f604 commit 697ac87

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public function build(ContainerBuilder $container)
7272
public function getContainerExtension()
7373
{
7474
if (null === $this->extension) {
75-
$class = $this->getContainerExtensionClass();
76-
if (class_exists($class)) {
77-
$extension = new $class();
75+
$extension = $this->createContainerExtension();
7876

77+
if (null !== $extension) {
7978
// check naming convention
8079
$basename = preg_replace('/Bundle$/', '', $this->getName());
8180
$expectedAlias = Container::underscore($basename);
81+
8282
if ($expectedAlias != $extension->getAlias()) {
8383
throw new \LogicException(sprintf(
8484
'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.',
@@ -208,4 +208,16 @@ protected function getContainerExtensionClass()
208208

209209
return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
210210
}
211+
212+
/**
213+
* Creates the bundle's container extension.
214+
*
215+
* @return ExtensionInterface|null
216+
*/
217+
protected function createContainerExtension()
218+
{
219+
if (class_exists($class = $this->getContainerExtension())) {
220+
return new $class();
221+
}
222+
}
211223
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy