8000 Add path provider for bundle paths configuration · symfony/symfony@3ba28ae · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 3ba28ae

Browse files
committed
Add path provider for bundle paths configuration
1 parent b5f592e commit 3ba28ae

File tree

22 files changed

+299
-34
lines changed

22 files changed

+299
-34
lines changed

UPGRADE-4.4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ HttpFoundation
100100
HttpKernel
101101
----------
102102

103-
* Implementing the `BundleInterface` without implementing the `getPublicDir()` method is deprecated.
103+
* Implementing the `BundleInterface` without implementing the `getPaths()` method is deprecated.
104104
This method will be added to the interface in 5.0.
105105
* The `DebugHandlersListener` class has been marked as `final`
106106

UPGRADE-5.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ HttpFoundation
283283
HttpKernel
284284
----------
285285

286-
* The `getPublicDir()` method has been added to the `BundleInterface`.
286+
* The `getPaths()` method has been added to the `BundleInterface`.
287287
* Removed `Client`, use `HttpKernelBrowser` instead
288288
* The `Kernel::getRootDir()` and the `kernel.root_dir` parameter have been removed
289289
* The `KernelInterface::getName()` and the `kernel.name` parameter have been removed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ 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';
140+
if (method_exists($bundle, 'getPaths')) {
141+
$bundlePaths = $bundle->getPaths();
142+
$originDir = $bundlePaths['public_dir'] ?? $bundle->getPath().'/Resources/public';
143143
} else {
144-
$publicDir = ltrim($bundle->getPublicDir(), '\\/');
144+
$originDir = $bundle->getPath().'/Resources/public';
145145
}
146-
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.$publicDir)) {
146+
if (!is_dir($originDir)) {
147147
continue;
148148
}
149149

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
161161
// Override with provided Bundle info
162162
if (null !== $input->getArgument('bundle')) {
163163
try {
164+
$transPaths = [];
165+
$viewsPaths = [];
164166
$bundle = $kernel->getBundle($input->getArgument('bundle'));
165-
$transPaths = [$bundle->getPath().'/Resources/translations'];
167+
if (method_exists($bundle, 'getPaths')) {
168+
$bundlePaths = $bundle->getPaths();
169+
if (isset($bundlePaths['translations_dir'])) {
170+
$transPaths = [$bundlePaths['translations_dir']];
171+
}
172+
if (isset($bundlePaths['templates_dir'])) {
173+
$viewsPaths = [$bundlePaths['templates_dir']];
174+
}
175+
} else {
176+
$transPaths = [$bundle->getPath().'/Resources/translations'];
177+
$viewsPaths = [$bundle->getPath().'/Resources/views'];
178+
}
166179
if ($this->defaultTransPath) {
167180
$transPaths[] = $this->defaultTransPath;
168181
}
@@ -171,7 +184,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
171184
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $dir, $bundle->getName());
172185
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
173186
}
174-
$viewsPaths = [$bundle->getPath().'/Resources/views'];
175187
if ($this->defaultViewsPath) {
176188
$viewsPaths[] = $this->defaultViewsPath;
177189
}
@@ -206,13 +218,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
206218
}
207219
} elseif ($input->getOption('all')) {
208220
foreach ($kernel->getBundles() as $bundle) {
209-
$transPaths[] = $bundle->getPath().'/Resources/translations';
221+
if (method_exists($bundle, 'getPaths')) {
222+
$bundlePaths = $bundle->getPaths();
223+
if (isset($bundlePaths['translations_dir'])) {
224+
$transPaths[] = $bundlePaths['translations_dir'];
225+
}
226+
if (isset($bundlePaths['templates_dir'])) {
227+
$viewsPaths[] = $bundlePaths['templates_dir'];
228+
}
229+
} else {
230+
$transPaths[] = $bundle->getPath().'/Resources/translations';
231+
$viewsPaths[] = $bundle->getPath().'/Resources/views';
232+
}
210233
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
211234
$transPaths[] = $deprecatedPath;
212235
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $deprecatedPath);
213236
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
214237
}
215-
$viewsPaths[] = $bundle->getPath().'/Resources/views';
216238
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
217239
$viewsPaths[] = $deprecatedPath;
218240
$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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
153153
// Override with provided Bundle info
154154
if (null !== $input->getArgument('bundle')) {
155155
try {
156+
$transPaths = [];
157+
$viewsPaths = [];
156158
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
157-
$transPaths = [$foundBundle->getPath().'/Resources/translations'];
159+
if (method_exists($foundBundle, 'getPaths')) {
160+
$bundlePaths = $foundBundle->getPaths();
161+
if (isset($bundlePaths['translations_dir'])) {
162+
$transPaths = [$bundlePaths['translations_dir']];
163+
}
164+
if (isset($bundlePaths['templates_dir'])) {
165+
$viewsPaths = [$bundlePaths['templates_dir']];
166+
}
167+
} else {
168+
$transPaths = [$foundBundle->getPath().'/Resources/translations'];
169+
$viewsPaths = [$foundBundle->getPath().'/Resources/views'];
170+
}
158171
if ($this->defaultTransPath) {
159172
$transPaths[] = $this->defaultTransPath;
160173
}
@@ -163,7 +176,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
163176
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $foundBundle->getName(), $dir);
164177
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
165178
}
166-
$viewsPaths = [$foundBundle->getPath().'/Resources/views'];
167179
if ($this->defaultViewsPath) {
168180
$viewsPaths[] = $this->defaultViewsPath;
169181
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11431143
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
11441144
$rootDir = $container->getParameter('kernel.root_dir');
11451145
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
1146-
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
1146+
if ($container->fileExists($dir = $bundle['paths']['translations_dir'] ?? $bundle['path'].'/Resources/translations')) {
11471147
$dirs[] = $dir;
11481148
} else {
11491149
$nonExistingDirs[] = $dir;
@@ -1305,20 +1305,20 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
13051305
}
13061306

13071307
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
1308-
$dirname = $bundle['path'];
1308+
$configDir = $bundle['paths']['config_dir'] ?? $bundle['path'].'/Resources/config';
13091309

13101310
if (
1311-
$container->fileExists($file = $dirname.'/Resources/config/validation.yaml', false) ||
1312-
$container->fileExists($file = $dirname.'/Resources/config/validation.yml', false)
1311+
$container->fileExists($file = $configDir.'/validation.yaml', false) ||
1312+
$container->fileExists($file = $configDir.'/validation.yml', false)
13131313
) {
13141314
$fileRecorder('yml', $file);
13151315
}
13161316

1317-
if ($container->fileExists($file = $dirname.'/Resources/config/validation.xml', false)) {
1317+
if ($container->fileExists($file = $configDir.'/validation.xml', false)) {
13181318
$fileRecorder('xml', $file);
13191319
}
13201320

1321-
if ($container->fileExists($dir = $dirname.'/Resources/config/validation', '/^$/')) {
1321+
if ($container->fileExists($dir = $configDir.'/validation', '/^$/')) {
13221322
$this->registerMappingFilesFromDir($dir, $fileRecorder);
13231323
}
13241324
}
@@ -1499,20 +1499,20 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
14991499
};
15001500

15011501
foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
1502-
$dirname = $bundle['path'];
1502+
$configDir = $bundle['paths']['config_dir'] ?? $bundle['path'].'/Resources/config';
15031503

1504-
if ($container->fileExists($file = $dirname.'/Resources/config/serialization.xml', false)) {
1504+
if ($container->fileExists($file = $configDir.'/serialization.xml', false)) {
15051505
$fileRecorder('xml', $file);
15061506
}
15071507

15081508
if (
1509-
$container->fileExists($file = $dirname.'/Resources/config/serialization.yaml', false) ||
1510-
$container->fileExists($file = $dirname.'/Resources/config/serialization.yml', false)
1509+
$container->fileExists($file = $configDir.'/serialization.yaml', false) ||
1510+
$container->fileExists($file = $configDir.'/serialization.yml', false)
15111511
) {
15121512
$fileRecorder('yml', $file);
15131513
}
15141514

1515-
if ($container->fileExists($dir = $dirname.'/Resources/config/serialization', '/^$/')) {
1515+
if ($container->fileExists($dir = $configDir.'/serialization', '/^$/')) {
15161516
$this->registerMappingFilesFromDir($dir, $fileRecorder);
15171517
}
15181518
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class ModernBundle extends Bundle
17+
{
18+
public function getPaths(): array
19+
{
20+
$bundlePath = $this->getPath();
21+
22+
return [
23+
'config_dir' => $bundlePath.'/config',
24+
'public_dir' => $bundlePath.'/public',
25+
'templates_dir' => $bundlePath.'/templates',
26+
'translations_dir' => $bundlePath.'/translations',
27+
];
28+
}
29+
}
Lines 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\Person:
2+
attributes:
3+
name:
4+
serialized_name: 'full_name'
Lines 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\Person:
2+
properties:
3+
age:
4+
- GreaterThan:
5+
value: 18

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

Whitespace-only changes.

0 commit comments

Comments
 (0)
0