Skip to content

Commit 39575e9

Browse files
bug #46385 [HttpKernel] New bundle path convention when AbstractBundle is used (yceruto)
This PR was merged into the 6.1 branch. Discussion ---------- [HttpKernel] New bundle path convention when `AbstractBundle` is used | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | symfony/symfony-docs#16801 Addressing this comment symfony/symfony-docs#16801 (comment) Since Symfony 6.1 when any bundle starts using the new `AbstractBundle` and the bundle is placed in the `src/` directory we automatically update this path to the parent directory, so we don't have to do it manually to use [the modern bundle directory structure](https://symfony.com/doc/current/bundles/best_practices.html#directory-structure). As far as I can see, there is no BC break on this proposal as this is a new class introduced in 6.1 and you have to update your code to make this happen. I will add a note about this subject in the doc too. Commits ------- 1193ed2 New bundle path convention when AbstractBundle is used
2 parents 123b165 + 1193ed2 commit 39575e9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,18 @@ public function getContainerExtension(): ?ExtensionInterface
4747

4848
return $this->extension ??= new BundleExtension($this, $this->extensionAlias);
4949
}
50+
51+
/**
52+
* {@inheritdoc}
53+
*/
54+
public function getPath(): string
55+
{
56+
if (null === $this->path) {
57+
$reflected = new \ReflectionObject($this);
58+
// assume the modern directory structure by default
59+
$this->path = \dirname($reflected->getFileName(), 2);
60+
}
61+
62+
return $this->path;
63+
}
5064
}

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* Add `Profiler::isEnabled()` so collaborating collector services may elect to omit themselves
1111
* Add the `UidValueResolver` argument value resolver
1212
* Add `AbstractBundle` class for DI configuration/definition on a single file
13+
* Update the path of a bundle placed in the `src/` directory to the parent directory when `AbstractBundle` is used
1314

1415
6.0
1516
---

0 commit comments

Comments
 (0)