{"record":{"id":"b183773fd13260a2","repo":"symfony/http-kernel","slug":"users-will-expect-the-alias-of-the-default-extension-of-a","errorCode":null,"errorMessage":"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.","messagePattern":"Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name \\(\"(.+?)\"\\)\\. You can override \"Bundle::getContainerExtension\\(\\)\" if you want to use \"(.+?)\" or another alias\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Bundle/Bundle.php","lineNumber":48,"sourceCode":"     *\n     * @throws \\LogicException\n     */\n    public function getContainerExtension(): ?ExtensionInterface\n    {\n        if (!isset($this->extension)) {\n            $extension = $this->createContainerExtension();\n\n            if (null !== $extension) {\n                if (!$extension instanceof ExtensionInterface) {\n                    throw new \\LogicException(\\sprintf('Extension \"%s\" must implement Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface.', get_debug_type($extension)));\n                }\n\n                // check naming convention\n                $basename = preg_replace('/Bundle$/', '', $this->getName());\n                $expectedAlias = Container::underscore($basename);\n\n                if ($expectedAlias != $extension->getAlias()) {\n                    throw new \\LogicException(\\sprintf('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.', $expectedAlias, $extension->getAlias()));\n                }\n\n                $this->extension = $extension;\n            } else {\n                $this->extension = false;\n            }\n        }\n\n        return $this->extension ?: null;\n    }\n\n    public function getNamespace(): string\n    {\n        return $this->namespace ??= false === ($pos = strrpos(static::class, '\\\\')) ? '' : substr(static::class, 0, $pos);\n    }\n\n    public function getPath(): string\n    {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Bundle/Bundle.php#L30-L66","documentation":"Symfony's Bundle::getContainerExtension() auto-discovers a bundle's DependencyInjection extension and enforces the naming convention: the extension alias must be the underscored version of the bundle name with the \"Bundle\" suffix stripped (e.g. AcmeFooBundle -> acme_foo). A LogicException is thrown when the extension class exists but its getAlias() returns something else, because container parameter/keys would confuse users.","triggerScenarios":"Registering a bundle whose Extension class (e.g. AcmeFooBundle\\DependencyInjection\\AcmeFooExtension) returns an alias from getAlias() that does not equal Container::underscore('AcmeFoo'); typically when getAlias() is overridden to return a custom string, or the extension class name deviates from the convention so the parent getAlias() fallback derives a wrong alias.","commonSituations":"Renaming a bundle without renaming its Extension class or alias; hand-writing getAlias() to a shorter/prettier name like 'foo' while the bundle is 'AcmeFooBundle'; copying an extension from another bundle and forgetting to update getAlias().","solutions":["Rename the extension's getAlias() return value to Container::underscore(basename-without-Bundle-suffix), e.g. return 'acme_foo';","Alternatively rename the Extension class so the conventional getAlias() computes the correct alias automatically.","If a non-conventional alias is truly intended, override Bundle::getContainerExtension() explicitly (as the message says) so the convention check is bypassed."],"exampleFix":"// before\nclass AcmeFooExtension extends Extension\n{\n    public function getAlias(): string\n    {\n        return 'foo';\n    }\n}\n// after\nclass AcmeFooExtension extends Extension\n{\n    public function getAlias(): string\n    {\n        return 'acme_foo';\n    }\n}","handlingStrategy":"validation","validationCode":"$expected = \\Symfony\\Component\\DependencyInjection\\Container::underscore(preg_replace('/Bundle$/', '', $bundle->getName()));\nif ($extension->getAlias() !== $expected) {\n    // fix alias before registering\n}","typeGuard":null,"tryCatchPattern":"try { $ext = $bundle->getContainerExtension(); } catch (\\LogicException $e) { /* fix extension alias in DI extension class */ }","preventionTips":["Never override getAlias() unless you also override getContainerExtension()","Follow the <Vendor><Name>Extension naming convention matching the bundle name","Test bundle registration in a smoke test so alias mismatches surface in CI"],"tags":["symfony","bundle","dependency-injection","naming-convention"],"backgroundTag":"invalid-identifier-format","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}