8000 [FrameworkBundle] Deprecate support for legacy translations and views… · symfony/symfony@f7913b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f7913b8

Browse files
author
Robin Chalas
committed
[FrameworkBundle] Deprecate support for legacy translations and views directories
1 parent 031762e commit f7913b8

File tree

7 files changed

+151
-26
lines changed

7 files changed

+151
-26
lines changed

UPGRADE-4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ FrameworkBundle
155155
* The `--no-debug` console option has been deprecated,
156156
set the "APP_DEBUG" environment variable to "0" instead.
157157
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been deprecated, use the `trans()` one instead with a `%count%` parameter.
158+
* Deprecated support for legacy directory structure in `translation:update` and `translation:debug` comands.
158159

159160
Messenger
160161
---------

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ FrameworkBundle
169169
* The `--no-debug` console option has been removed,
170170
set the "APP_DEBUG" environment variable to "0" instead.
171171
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been removed, use the `trans()` one instead with a `%count%` parameter.
172+
* Removed support for legacy directory structure in `translation:update` and `translation:debug` comands.
172173

173174
HttpFoundation
174175
--------------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ CHANGELOG
2424
* Deprecated `CachePoolClearerPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolClearerPass` instead.
2525
* Deprecated `CachePoolPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolPass` instead.
2626
* Deprecated `CachePoolPrunerPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolPrunerPass` instead.
27+
* Deprecated support for legacy directory structure in `translation:update` and `translation:debug` comands.
2728

2829
4.1.0
2930
-----

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

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
131131
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');
132132

133133
// Define Root Paths
134-
$transPaths = array($rootDir.'/Resources/translations');
134+
$transPaths = array();
135+
if (is_dir($dir = $rootDir.'/Resources/translations')) {
136+
if ($dir !== $this->defaultTransPath) {
137+
$notice = sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2. ', $dir);
138+
@trigger_error($notice.($this->defaultTransPath ? sprintf('Use the "%s" directory instead.', $this->defaultTransPath) : 'Configure and use "translator.default_path" instead.'), E_USER_DEPRECATED);
139+
}
140+
$transPaths[] = $dir;
141+
}
135142
if ($this->defaultTransPath) {
136143
$transPaths[] = $this->defaultTransPath;
137144
}
138-
$viewsPaths = array($rootDir.'/Resources/views');
145+
$viewsPaths = array();
146+
if (is_dir($dir = $rootDir.'/Resources/views')) {
147+
if ($dir !== $this->defaultViewsPath) {
148+
$notice = sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2. ', $dir);
149+
@trigger_error($notice.($this->defaultViewsPath ? sprintf('Use the "%s" directory instead.', $this->defaultViewsPath) : 'Configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
150+
}
151+
$viewsPaths[] = $dir;
152+
}
139153
if ($this->defaultViewsPath) {
140154
$viewsPaths[] = $this->defaultViewsPath;
141155
}
@@ -146,20 +160,43 @@ protected function execute(InputInterface $input, OutputInterface $output)
146160
$bundle = $kernel->getBundle($input->getArgument('bundle'));
147161
$transPaths = array($bundle->getPath().'/Resources/translations');
148162
if ($this->defaultTransPath) {
149-
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
163+
$transPaths[] = $this->defaultTransPath.'/bundles/'.$bundle->getName();
164+
}
165+
if (is_dir($dir = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
166+
$transPaths[] = $dir;
167+
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2. ', $dir, $bundle->getName());
168+
@trigger_error($notice.($this->defaultTransPath ? sprintf('Use the "%s" directory instead.', $this->defaultTransPath.'/bundles/'.$bundle->getName()) : sprintf('Configure "translator.default_path" and create a "bundles/%s/" directory into it instead.', $bundle->getName())), E_USER_DEPRECATED);
150169
}
151-
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName());
152170
$viewsPaths = array($bundle->getPath().'/Resources/views');
153171
if ($this->defaultViewsPath) {
154172
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
155173
}
156-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName());
174+
if (is_dir($dir = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
175+
$viewsPaths[] = $dir;
176+
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2. ', $bundle->getName(), $dir);
177+
@trigger_error($notice.($this->defaultViewsPath ? sprintf('Use the "%s" directory instead.', $this->defaultViewsPath.'/bundles/'.$bundle->getName()) : sprintf('Configure "twig.default_path" and create a "bundles/%s/" directory into it instead.', $bundle->getName())), E_USER_DEPRECATED);
178+
}
157179
} catch (\InvalidArgumentException $e) {
158180
// such a bundle does not exist, so treat the argument as path
159-
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
160-
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
181+
$path = $input->getArgument('bundle');
161182

162-
if (!is_dir($transPaths[0])) {
183+
$transPaths = array($path.'/translations');
184+
if (is_dir($dir = $path.'/Resources/translations')) {
185+
if ($dir !== $this->defaultTransPath) {
186+
@trigger_error(sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2. Use the "%s" directory instead.', $dir, $path.'/translations'), E_USER_DEPRECATED);
187+
}
188+
$transPaths[] = $dir;
189+
}
190+
191+
$viewsPaths = array($path.'/templates');
192+
if (is_dir($dir = $path.'/Resources/views')) {
193+
if ($dir !== $this->defaultViewsPath) {
194+
@trigger_error(sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2. Use the "%s" directory instead.', $dir, $path.'/templates'), E_USER_DEPRECATED);
195+
}
196+
$viewsPaths[] = $dir;
197+
}
198+
199+
if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
163200
throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
164201
}
165202
}
@@ -169,12 +206,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
169206
if ($this->defaultTransPath) {
170207
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
171208
}
172-
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName());
173-
$viewsPaths[] = $bundle->getPath().'/Resources/views';
209+
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
210+
$transPaths[] = $deprecatedPath;
211+
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2. ', $bundle->getName(), $deprecatedPath);
212+
@trigger_error($notice.($this->defaultTransPath ? sprintf('Use the "%s" directory instead.', $this->defaultTransPath.'/bundles/'.$bundle->getName()) : 'Configure "translator.default_path" and create a "%s/" directory into it instead.'), E_USER_DEPRECATED);
213+
}
214+
$viewsPaths[] = array($bundle->getPath().'/Resources/views');
174215
if ($this->defaultViewsPath) {
175216
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
176217
}
177-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName());
218+
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
219+
$viewsPaths[] = $deprecatedPath;
220+
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2. ', $bundle->getName(), $deprecatedPath);
221+
@trigger_error($notice.($this->defaultViewsPath ? sprintf('Use the "%s" directory instead.', $this->defaultViewsPath.'/bundles/'.$bundle->getName()) : sprintf('Configure "twig.default_path" and create a "bundles/%s/" directory into it instead.', $bundle->getName())), E_USER_DEPRECATED);
222+
}
178223
}
179224
}
180225

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

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
121121
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');
122122

123123
// Define Root Paths
124-
$transPaths = array($rootDir.'/Resources/translations');
124+
$transPaths = array();
125+
if (is_dir($dir = $rootDir.'/Resources/translations')) {
126+
if ($dir !== $this->defaultTransPath) {
127+
$notice = sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2. ', $dir);
128+
@trigger_error($notice.($this->defaultTransPath ? sprintf('Use the "%s" directory instead.', $this->defaultTransPath) : 'Configure and use "translator.default_path" instead.'), E_USER_DEPRECATED);
129+
}
130+
$transPaths[] = $dir;
131+
}
125132
if ($this->defaultTransPath) {
126133
$transPaths[] = $this->defaultTransPath;
127134
}
128-
$viewsPaths = array($rootDir.'/Resources/views');
135+
$viewsPaths = array();
136+
if (is_dir($dir = $rootDir.'/Resources/views')) {
137+
if ($dir !== $this->defaultViewsPath) {
138+
$notice = sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2. ', $dir);
139+
@trigger_error($notice.($this->defaultViewsPath ? sprintf('Use the "%s" directory instead.', $this->defaultViewsPath) : 'Configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
140+
}
141+
$viewsPaths[] = $dir;
142+
}
129143
if ($this->defaultViewsPath) {
130144
$viewsPaths[] = $this->defaultViewsPath;
131145
}
@@ -139,20 +153,42 @@ protected function execute(InputInterface $input, OutputInterface $output)
139153
if ($this->defaultTransPath) {
140154
$transPaths[] = $this->defaultTransPath.'/'.$foundBundle->getName();
141155
}
142-
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $foundBundle->getName());
156+
if (is_dir($dir = sprintf('%s/Resources/%s/translations', $rootDir, $foundBundle->getName()))) {
157+
$transPaths[] = $dir;
158+
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2. ', $foundBundle->getName(), $dir);
159+
@trigger_error($notice.($this->defaultTransPath ? sprintf('Use the "%s" directory instead.', $this->defaultTransPath.'/bundles/'.$foundBundle->getName()) : 'Configure "translator.default_path" and create a "bundles/%s/" directory into it instead.'), E_USER_DEPRECATED);
160+
}
143161
$viewsPaths = array($foundBundle->getPath().'/Resources/views');
144162
i B41A f ($this->defaultViewsPath) {
145163
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$foundBundle->getName();
146164
}
147-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $foundBundle->getName());
165+
if (is_dir($dir = sprintf('%s/Resources/%s/views', $rootDir, $foundBundle->getName()))) {
166+
$viewsPaths[] = $dir;
167+
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2. ', $foundBundle->getName(), $dir);
168+
@trigger_error($notice.($this->defaultViewsPath ? sprintf('Use the "%s" directory instead.', $this->defaultViewsPath.'/bundles/'.$foundBundle->getName()) : sprintf('Configure "twig.default_path" and create a "bundles/%s/" directory into it instead.', $foundBundle->getName())), E_USER_DEPRECATED);
169+
}
148170
$currentName = $foundBundle->getName();
149171
} catch (\InvalidArgumentException $e) {
150172
// such a bundle does not exist, so treat the argument as path
151-
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
152-
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
153-
$currentName = $transPaths[0];
173+
$path = $input->getArgument('bundle');
174+
175+
$transPaths = array($path.'/translations');
176+
if (is_dir($dir = $path.'/Resources/translations')) {
177+
if ($dir !== $this->defaultTransPath) {
178+
@trigger_error(sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2. Use the "%s" directory instead.', $dir, $path.'/translations'), E_USER_DEPRECATED);
179+
}
180+
$transPaths[] = $dir;
181+
}
182+
183+
$viewsPaths = array($path.'/templates');
184+
if (is_dir($dir = $path.'/Resources/views')) {
185+
if ($dir !== $this->defaultViewsPath) {
186+
@trigger_error(sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2. Use the "%s" directory instead.', $dir, $path.'/templates'), E_USER_DEPRECATED);
187+
}
188+
$viewsPaths[] = $dir;
189+
}
154190

155-
if (!is_dir($transPaths[0])) {
191+
if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
156192
throw new InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
157193
}
158194
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ public function testDebugDefaultDirectory()
6565
$this->assertRegExp('/unused/', $tester->getDisplay());
6666
}
6767

68+
/**
69+
* @group legacy
70+
* @expectedDeprecation Storing translations in the "%ssf_translation%s/Resources/translations" directory is deprecated since Symfony 4.2. Use the "%ssf_translation%s/translations" directory instead.
71+
* @expectedDeprecation Storing templates in the "%ssf_translation%s/Resources/views" directory is deprecated since Symfony 4.2. Use the "%ssf_translation%s/templates" directory instead.
72+
*/
73+
public function testDebugLegacyDefaultDirectory()
74+
{
75+
$this->fs->mkdir($this->translationDir.'/Resources/translations');
76+
$this->fs->mkdir($this->translationDir.'/Resources/views');
77+
78+
$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'));
79+
$tester->execute(array('locale' => 'en'));
80+
81+
$this->assertRegExp('/missing/', $tester->getDisplay());
82+
$this->assertRegExp('/unused/', $tester->getDisplay());
83+
}
84+
6885
public function testDebugDefaultRootDirectory()
6986
{
7087
$this->fs->remove($this->translationDir);
@@ -82,14 +99,16 @@ public function testDebugDefaultRootDirectory()
8299

83100
public function testDebugCustomDirectory()
84101
{
102+
$this->fs->mkdir($this->translationDir.'/customDir/translations');
103+
$this->fs->mkdir($this->translationDir.'/customDir/templates');
85104
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
86105
$kernel->expects($this->once())
87106
->method('getBundle')
88-
->with($this->equalTo($this->translationDir))
107+
->with($this->equalTo($this->translationDir.'/customDir'))
89108
->willThrowException(new \InvalidArgumentException());
90109

91110
$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'), $kernel);
92-
$tester->execute(array('locale' => 'en', 'bundle' => $this->translationDir));
111+
$tester->execute(array('locale' => 'en', 'bundle' => $this->translationDir.'/customDir'));
93112

94113
$this->assertRegExp('/missing/', $tester->getDisplay());
95114
$this->assertRegExp('/unused/', $tester->getDisplay());
@@ -114,10 +133,12 @@ protected function setUp()
114133
{
115134
$this->fs = new Filesystem();
116135
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
117-
$this->fs->mkdir($this->translationDir.'/Resources/translations');
118-
$this->fs->mkdir($this->translationDir.'/Resources/views');
119136
$this->fs->mkdir($this->translationDir.'/translations');
120137
$this->fs->mkdir($this->translationDir.'/templates');
138+
$this->fs->mkdir($this->translationDir.'/translation/bundles/foo');
139+
$this->fs->mkdir($this->translationDir.'/translations/bundles/bar');
140+
$this->fs->mkdir($this->translationDir.'/templates/bundles/foo');
141+
$this->fs->mkdir($this->translationDir.'/templates/bundles/bar');
121142
}
122143

123144
protected function tearDown()

0 commit comments

Comments
 (0)
0