Skip to content

Commit b64fdb7

Browse files
Merge branch '4.4'
* 4.4: [HttpKernel][FrameworkBundle] Add alternative convention for bundle directories [DI] deprecate support for non-object services [Translation] XliffLintCommand: allow .xliff file extension [Serializer] Encode empty objects as objects, not arrays
2 parents 60f5da0 + 50c5911 commit b64fdb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+443
-97
lines changed

UPGRADE-4.4.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,33 @@ HttpFoundation
113113
HttpKernel
114114
----------
115115

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

120144
Lock
121145
----

UPGRADE-5.0.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ HttpFoundation
291291
HttpKernel
292292
----------
293293

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

312337
Intl
313338
----

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

Lines 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
133133
$validAssetDirs = [];
134134
/** @var BundleInterface $bundle */
135135
foreach ($kernel->getBundles() as $bundle) {
136-
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.ltrim($bundle->getPublicDir(), '\\/'))) {
136+
if (!is_dir($originDir = $bundle->getPath().'/Resources/public') && !is_dir($originDir = $bundle->getPath().'/public')) {
137137
continue;
138138
}
139139

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
140140
if (null !== $input->getArgument('bundle')) {
141141
try {
142142
$bundle = $kernel->getBundle($input->getArgument('bundle'));
143-
$transPaths = [$bundle->getPath().'/Resources/translations'];
143+
$bundleDir = $bundle->getPath();
144+
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
145+
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
144146
if ($this->defaultTransPath) {
145147
$transPaths[] = $this->defaultTransPath;
146148
}
147-
$viewsPaths = [$bundle->getPath().'/Resources/views'];
148149
if ($this->defaultViewsPath) {
149150
$viewsPaths[] = $this->defaultViewsPath;
150151
}
@@ -161,8 +162,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
161162
}
162163
} elseif ($input->getOption('all')) {
163164
foreach ($kernel->getBundles() as $bundle) {
164-
$transPaths[] = $bundle->getPath().'/Resources/translations';
165-
$viewsPaths[] = $bundle->getPath().'/Resources/views';
165+
$bundleDir = $bundle->getPath();
166+
$transPaths[] = is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundle->getPath().'/translations';
167+
$viewsPaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
166168
}
167169
}
168170

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
139139
if (null !== $input->getArgument('bundle')) {
140140
try {
141141
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
142-
$transPaths = [$foundBundle->getPath().'/Resources/translations'];
142+
$bundleDir = $foundBundle->getPath();
143+
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
144+
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
143145
if ($this->defaultTransPath) {
144146
$transPaths[] = $this->defaultTransPath;
145147
}
146-
$viewsPaths = [$foundBundle->getPath().'/Resources/views'];
147148
if ($this->defaultViewsPath) {
148149
$viewsPaths[] = $this->defaultViewsPath;
149150
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
10271027
}
10281028
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
10291029
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
1030-
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
1030+
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations') || $container->fileExists($dir = $bundle['path'].'/translations')) {
10311031
$dirs[] = $dir;
10321032
} else {
10331033
$nonExistingDirs[] = $dir;
@@ -1167,20 +1167,20 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
11671167
}
11681168

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

11721172
if (
1173-
$container->fileExists($file = $dirname.'/Resources/config/validation.yaml', false) ||
1174-
$container->fileExists($file = $dirname.'/Resources/config/validation.yml', false)
1173+
$container->fileExists($file = $configDir.'/validation.yaml', false) ||
1174+
$container->fileExists($file = $configDir.'/validation.yml', false)
11751175
) {
11761176
$fileRecorder('yml', $file);
11771177
}
11781178

1179-
if ($container->fileExists($file = $dirname.'/Resources/config/validation.xml', false)) {
1179+
if ($container->fileExists($file = $configDir.'/validation.xml', false)) {
11801180
$fileRecorder('xml', $file);
11811181
}
11821182

1183-
if ($container->fileExists($dir = $dirname.'/Resources/config/validation', '/^$/')) {
1183+
if ($container->fileExists($dir = $configDir.'/validation', '/^$/')) {
11841184
$this->registerMappingFilesFromDir($dir, $fileRecorder);
11851185
}
11861186
}
@@ -1352,20 +1352,20 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
13521352
};
13531353

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

1357-
if ($container->fileExists($file = $dirname.'/Resources/config/serialization.xml', false)) {
1357+
if ($container->fileExists($file = $configDir.'/serialization.xml', false)) {
13581358
$fileRecorder('xml', $file);
13591359
}
13601360

13611361
if (
1362-
$container->fileExists($file = $dirname.'/Resources/config/serialization.yaml', false) ||
1363-
$container->fileExists($file = $dirname.'/Resources/config/serialization.yml', false)
1362+
$container->fileExists($file = $configDir.'/serialization.yaml', false) ||
1363+
$container->fileExists($file = $configDir.'/serialization.yml', false)
13641364
) {
13651365
$fileRecorder('yml', $file);
13661366
}
13671367

1368-
if ($container->fileExists($dir = $dirname.'/Resources/config/serialization', '/^$/')) {
1368+
if ($container->fileExists($dir = $configDir.'/serialization', '/^$/')) {
13691369
$this->registerMappingFilesFromDir($dir, $fileRecorder);
13701370
}
13711371
}
Lines 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+
}
Lines 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'

0 commit comments

Comments
 (0)