Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6996e1c

Browse filesBrowse files
ycerutonicolas-grekas
authored andcommitted
[HttpKernel][FrameworkBundle] Add alternative convention for bundle directories
1 parent 6723bb9 commit 6996e1c
Copy full SHA for 6996e1c

File tree

Expand file treeCollapse file tree

29 files changed

+308
-42
lines changed
Filter options
Expand file treeCollapse file tree

29 files changed

+308
-42
lines changed

‎UPGRADE-4.4.md

Copy file name to clipboardExpand all lines: UPGRADE-4.4.md
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,33 @@ HttpFoundation
108108
HttpKernel
109109
----------
110110

111-
* Implementing the `BundleInterface` without implementing the `getPublicDir()` method is deprecated.
112-
This method will be added to the interface in 5.0.
113111
* The `DebugHandlersListener` class has been marked as `final`
112+
* Added new Bundle directory convention consistent with standard skeletons:
113+
114+
```
115+
└── MyBundle/
116+
├── config/
117+
├── public/
118+
├── src/
119+
│ └── MyBundle.php
120+
├── templates/
121+
└── translations/
122+
```
123+
124+
To make this work properly, it is necessary to change the root path of the bundle:
125+
126+
```php
127+
class MyBundle extends Bundle
128+
{
129+
public function getPath(): string
130+
{
131+
return \dirname(__DIR__);
132+
}
133+
}
134+
```
135+
136+
As many bundles must be compatible with a range of Symfony versions, the current
137+
directory convention is not deprecated yet, but it will be in the future.
114138

115139
Lock
116140
----

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+26-1Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ HttpFoundation
286286
HttpKernel
287287
----------
288288

289-
* The `getPublicDir()` method has been added to the `BundleInterface`.
290289
* Removed `Client`, use `HttpKernelBrowser` instead
291290
* The `Kernel::getRootDir()` and the `kernel.root_dir` parameter have been removed
292291
* The `KernelInterface::getName()` and the `kernel.name` parameter have been removed
@@ -303,6 +302,32 @@ HttpKernel
303302
* Removed `TranslatorListener` in favor of `LocaleAwareListener`
304303
* The `DebugHandlersListener` class has been made `final`
305304
* Removed `SaveSessionListener` in favor of `AbstractSessionListener`
305+
* Added new Bundle directory convention consistent with standard skeletons:
306+
307+
```
308+
└── MyBundle/
309+
├── config/
310+
├── public/
311+
├── src/
312+
│ └── MyBundle.php
313+
├── templates/
314+
└── translations/
315+
```
316+
317+
To make this work properly, it is necessary to change the root path of the bundle:
318+
319+
```php
320+
class MyBundle extends Bundle
321+
{
322+
public function getPath(): string
323+
{
324+
return \dirname(__DIR__);
325+
}
326+
}
327+
```
328+
329+
As many bundles must be compatible with a range of Symfony versions, the current
330+
directory convention is not deprecated yet, but it will be in the future.
306331

307332
Intl
308333
----

‎src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/DoctrineValidationPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/DoctrineValidationPass.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ private function updateValidatorMappingFiles(ContainerBuilder $container, string
4848
}
4949

5050
$files = $container->getParameter('validator.mapping.loader.'.$mapping.'_files_loader.mapping_files');
51-
$validationPath = 'Resources/config/validation.'.$this->managerType.'.'.$extension;
51+
$validationPath = '/config/validation.'.$this->managerType.'.'.$extension;
5252

53-
foreach ($container->getParameter('kernel.bundles') as $bundle) {
54-
$reflection = new \ReflectionClass($bundle);
55-
if ($container->fileExists($file = \dirname($reflection->getFileName()).'/'.$validationPath)) {
53+
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
54+
if ($container->fileExists($file = $bundle['path'].'/Resources'.$validationPath) || $container->fileExists($file = $bundle['path'].$validationPath)) {
5655
$files[] = $file;
5756
}
5857
}

‎src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
137137
$validAssetDirs = [];
138138
/** @var BundleInterface $bundle */
139139
foreach ($kernel->getBundles() as $bundle) {
140-
if (!method_exists($bundle, 'getPublicDir')) {
141-
@trigger_error(sprintf('Not defining "getPublicDir()" method in the "%s" class is deprecated since Symfony 4.4 and will not be supported in 5.0.', \get_class($bundle)), E_USER_DEPRECATED);
142-
$publicDir = 'Resources/public';
143-
} else {
144-
$publicDir = ltrim($bundle->getPublicDir(), '\\/');
145-
}
146-
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.$publicDir)) {
140+
if (!is_dir($originDir = $bundle->getPath().'/Resources/public') && !is_dir($originDir = $bundle->getPath().'/public')) {
147141
continue;
148142
}
149143

‎src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
162162
if (null !== $input->getArgument('bundle')) {
163163
try {
164164
$bundle = $kernel->getBundle($input->getArgument('bundle'));
165-
$transPaths = [$bundle->getPath().'/Resources/translations'];
165+
$bundleDir = $bundle->getPath();
166+
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
167+
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
166168
if ($this->defaultTransPath) {
167169
$transPaths[] = $this->defaultTransPath;
168170
}
@@ -171,7 +173,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
171173
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $dir, $bundle->getName());
172174
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
173175
}
174-
$viewsPaths = [$bundle->getPath().'/Resources/views'];
175176
if ($this->defaultViewsPath) {
176177
$viewsPaths[] = $this->defaultViewsPath;
177178
}
@@ -206,13 +207,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
206207
}
207208
} elseif ($input->getOption('all')) {
208209
foreach ($kernel->getBundles() as $bundle) {
209-
$transPaths[] = $bundle->getPath().'/Resources/translations';
210+
$bundleDir = $bundle->getPath();
211+
$transPaths[] = is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundle->getPath().'/translations';
212+
$viewsPaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
210213
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
211214
$transPaths[] = $deprecatedPath;
212215
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $deprecatedPath);
213216
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
214217
}
215-
$viewsPaths[] = $bundle->getPath().'/Resources/views';
216218
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
217219
$viewsPaths[] = $deprecatedPath;
218220
$notice = sprintf('Loading Twig templates for "%s" from the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $deprecatedPath);

‎src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
154154
if (null !== $input->getArgument('bundle')) {
155155
try {
156156
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
157-
$transPaths = [$foundBundle->getPath().'/Resources/translations'];
157+
$bundleDir = $foundBundle->getPath();
158+
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
159+
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
158160
if ($this->defaultTransPath) {
159161
$transPaths[] = $this->defaultTransPath;
160162
}
@@ -163,7 +165,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
163165
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $foundBundle->getName(), $dir);
164166
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
165167
}
166-
$viewsPaths = [$foundBundle->getPath().'/Resources/views'];
167168
if ($this->defaultViewsPath) {
168169
$viewsPaths[] = $this->defaultViewsPath;
169170
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11521152
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
11531153
$rootDir = $container->getParameter('kernel.root_dir');
11541154
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
1155-
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
1155+
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations') || $container->fileExists($dir = $bundle['path'].'/translations')) {
11561156
$dirs[] = $dir;
11571157
} else {
11581158
$nonExistingDirs[] = $dir;
@@ -1314,20 +1314,20 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
13141314
}
13151315

13161316
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
1317-
$dirname = $bundle['path'];
1317+
$configDir = is_dir($bundle['path'].'/Resources/config') ? $bundle['path'].'/Resources/config' : $bundle['path'].'/config';
13181318

13191319
if (
1320-
$container->fileExists($file = $dirname.'/Resources/config/validation.yaml', false) ||
1321-
$container->fileExists($file = $dirname.'/Resources/config/validation.yml', false)
1320+
$container->fileExists($file = $configDir.'/validation.yaml', false) ||
1321+
$container->fileExists($file = $configDir.'/validation.yml', false)
13221322
) {
13231323
$fileRecorder('yml', $file);
13241324
}
13251325

1326-
if ($container->fileExists($file = $dirname.'/Resources/config/validation.xml', false)) {
1326+
if ($container->fileExists($file = $configDir.'/validation.xml', false)) {
13271327
$fileRecorder('xml', $file);
13281328
}
13291329

1330-
if ($container->fileExists($dir = $dirname.'/Resources/config/validation', '/^$/')) {
1330+
if ($container->fileExists($dir = $configDir.'/validation', '/^$/')) {
13311331
$this->registerMappingFilesFromDir($dir, $fileRecorder);
13321332
}
13331333
}
@@ -1508,20 +1508,20 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
15081508
};
15091509

15101510
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
1511-
$dirname = $bundle['path'];
1511+
$configDir = is_dir($bundle['path'].'/Resources/config') ? $bundle['path'].'/Resources/config' : $bundle['path'].'/config';
15121512

1513-
if ($container->fileExists($file = $dirname.'/Resources/config/serialization.xml', false)) {
1513+
if ($container->fileExists($file = $configDir.'/serialization.xml', false)) {
15141514
$fileRecorder('xml', $file);
15151515
}
15161516

15171517
if (
1518-
$container->fileExists($file = $dirname.'/Resources/config/serialization.yaml', false) ||
1519-
$container->fileExists($file = $dirname.'/Resources/config/serialization.yml', false)
1518+
$container->fileExists($file = $configDir.'/serialization.yaml', false) ||
1519+
$container->fileExists($file = $configDir.'/serialization.yml', false)
15201520
) {
15211521
$fileRecorder('yml', $file);
15221522
}
15231523

1524-
if ($container->fileExists($dir = $dirname.'/Resources/config/serialization', '/^$/')) {
1524+
if ($container->fileExists($dir = $configDir.'/serialization', '/^$/')) {
15251525
$this->registerMappingFilesFromDir($dir, $fileRecorder);
15261526
}
15271527
}
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity;
13+
14+
class LegacyPerson
15+
{
16+
public $name;
17+
public $age;
18+
19+
public function __construct(string $name, string $age)
20+
{
21+
$this->name = $name;
22+
$this->age = $age;
23+
}
24+
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class LegacyBundle extends Bundle
17+
{
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity\LegacyPerson:
2+
attributes:
3+
name:
4+
serialized_name: 'full_name'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity\LegacyPerson:
2+
properties:
3+
age:
4+
- GreaterThan:
5+
value: 18

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/LegacyBundle/Resources/public/legacy.css

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/LegacyBundle/Resources/public/legacy.css
Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ok_label: OK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src\Entity\ModernPerson:
2+
attributes:
3+
name:
4+
serialized_name: 'full_name'
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src\Entity\ModernPerson:
2+
properties:
3+
age:
4+
- GreaterThan:
5+
value: 18

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/ModernBundle/public/modern.css

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/ModernBundle/public/modern.css
Whitespace-only changes.
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src\Entity;
13+
14+
class ModernPerson
15+
{
16+
public $name;
17+
public $age;
18+
19+
public function __construct(string $name, string $age)
20+
{
21+
$this->name = $name;
22+
$this->age = $age;
23+
}
24+
}
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class ModernBundle extends Bundle
17+
{
18+
public function getPath(): string
19+
{
20+
return \dirname(__DIR__);
21+
}
22+
}
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ok_label: OK

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.