8000 Merge branch '3.4' into 4.0 · symfony/symfony@8b98282 · GitHub
[go: up one dir, main page]

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 8b98282

Browse files
Merge branch '3.4' into 4.0
* 3.4: [DI] Dont resolve envs in service ids Add tests proving it can load annotated files [WebProfilerBundle] Reset letter-spacing in toolbar Prefer overflow-wrap to word-break remove more kernel.root_dir parameter refs [*Bundle] Replace some kernel.root_dir by kernel.project_dir removed some phpdocs [Routing] Fix "config-file-relative" annotation loader resources Make search in debug:container command case-insensitive `resolveEnvPlaceholders` will return a mixed value Update translation commands to work with default paths [FrameworkBundle] Fix AssetsInstallCommand
2 parents 7a33b01 + f897542 commit 8b98282

Some content is hidden

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

41 files changed

+447
-122
lines changed

src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ private function createContainer()
4040
{
4141
$container = new ContainerBuilder(new ParameterBag(array(
4242
'kernel.cache_dir' => __DIR__,
43-
'kernel.root_dir' => __DIR__.'/Fixtures',
4443
'kernel.charset' => 'UTF-8',
4544
'kernel.debug' => true,
4645
'kernel.bundles' => array('DebugBundle' => 'Symfony\\Bundle\\DebugBundle\\DebugBundle'),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ private function absoluteSymlinkWithFallback(string $originDir, string $targetDi
226226
private function symlink(string $originDir, string $targetDir, bool $relative = false)
227227
{
228228
if ($relative) {
229+
$this->filesystem->mkdir(dirname($targetDir));
229230
$originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir)));
230231
}
231232
$this->filesystem->symlink($originDir, $targetDir);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ private function findServiceIdsContaining(ContainerBuilder $builder, $name)
221221
{
222222
$serviceIds = $builder->getServiceIds();
223223
$foundServiceIds = array();
224-
$name = strtolower($name);
225224
foreach ($serviceIds as $serviceId) {
226-
if (false === strpos($serviceId, $name)) {
225+
if (false === stripos($serviceId, $name)) {
227226
continue;
228227
}
229228
$foundServiceIds[] = $serviceId;

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

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ class TranslationDebugCommand extends Command
4646
private $translator;
4747
private $reader;
4848
private $extractor;
49+
private $defaultTransPath;
50+
private $defaultViewsPath;
4951

50-
public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor)
52+
public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultTransPath = null, string $defaultViewsPath = null)
5153
{
5254
parent::__construct();
5355

5456
$this->translator = $translator;
5557
$this->reader = $reader;
5658
$this->extractor = $extractor;
59+
$this->defaultTransPath = $defaultTransPath;
60+
$this->defaultViewsPath = $defaultViewsPath;
5761
}
5862

5963
/**
@@ -117,34 +121,56 @@ protected function execute(InputInterface $input, OutputInterface $output)
117121
/** @var KernelInterface $kernel */
118122
$kernel = $this->getApplication()->getKernel();
119123

120-
// Define Root Path to App folder
121-
$transPaths = array($kernel->getRootDir().'/Resources/');
124+
// Define Root Paths
125+
$transPaths = array($kernel->getRootDir().'/Resources/translations');
126+
if ($this->defaultTransPath) {
127+
$transPaths[] = $this->defaultTransPath;
128+
}
129+
$viewsPaths = array($kernel->getRootDir().'/Resources/views');
130+
if ($this->defaultViewsPath) {
131+
$viewsPaths[] = $this->defaultViewsPath;
132+
}
122133

123134
// Override with provided Bundle info
124135
if (null !== $input->getArgument('bundle')) {
125136
try {
126137
$bundle = $kernel->getBundle($input->getArgument('bundle'));
127-
$transPaths = array(
128-
$bundle->getPath().'/Resources/',
129-
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName()),
130-
);
138+
$transPaths = array($bundle->getPath().'/Resources/translations');
139+
if ($this->defaultTransPath) {
140+
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
141+
}
142+
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName());
143+
$viewsPaths = array($bundle->getPath().'/Resources/views');
144+
if ($this->defaultViewsPath) {
145+
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
146+
}
147+
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName());
131148
} catch (\InvalidArgumentException $e) {
132149
// such a bundle does not exist, so treat the argument as path
133-
$transPaths = array($input->getArgument('bundle').'/Resources/');
150+
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
151+
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
134152

135153
if (!is_dir($transPaths[0])) {
136154
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
137155
}
138156
}
139157
} elseif ($input->getOption('all')) {
140158
foreach ($kernel->getBundles() as $bundle) {
141-
$transPaths[] = $bundle->getPath().'/Resources/';
142-
$transPaths[] = sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName());
159+
$transPaths[] = $bundle->getPath().'/Resources/translations';
160+
if ($this->defaultTransPath) {
161+
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
162+
}
163+
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName());
164+
$viewsPaths[] = $bundle->getPath().'/Resources/views';
165+
if ($this->defaultViewsPath) {
166+
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
167+
}
168+
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName());
143169
}
144170
}
10000 145171

146172
// Extract used messages
147-
$extractedCatalogue = $this->extractMessages($locale, $transPaths);
173+
$extractedCatalogue = $this->extractMessages($locale, $viewsPaths);
148174

149175
// Load defined messages
150176
$currentCatalogue = $this->loadCurrentMessages($locale, $transPaths);
@@ -268,7 +294,6 @@ private function extractMessages(string $locale, array $transPaths): MessageCata
268294
{
269295
$extractedCatalogue = new MessageCatalogue($locale);
270296
foreach ($transPaths as $path) {
271-
$path = $path.'views';
272297
if (is_dir($path)) {
273298
$this->extractor->extract($path, $extractedCatalogue);
274299
}
@@ -281,7 +306,6 @@ private function loadCurrentMessages(string $locale, array $transPaths): Message
281306
{
282307
$currentCatalogue = new MessageCatalogue($locale);
283308
foreach ($transPaths as $path) {
284-
$path = $path.'translations';
285309
if (is_dir($path)) {
286310
$this->reader->read($path, $currentCatalogue);
287311
}
@@ -304,7 +328,6 @@ private function loadFallbackCatalogues(string $locale, array $transPaths): arra
304328

305329
$fallbackCatalogue = new MessageCatalogue($fallbackLocale);
306330
foreach ($transPaths as $path) {
307-
$path = $path.'translations';
308331
if (is_dir($path)) {
309332
$this->reader->read($path, $fallbackCatalogue);
310333
}

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Command\Command;
1515
use Symfony\Component\Console\Style\SymfonyStyle;
16+
use Symfony\Component\HttpKernel\KernelInterface;
1617
use Symfony\Component\Translation\Catalogue\TargetOperation;
1718
use Symfony\Component\Translation\Catalogue\MergeOperation;
1819
use Symfony\Component\Console\Input\InputInterface;
@@ -40,15 +41,19 @@ class TranslationUpdateCommand extends Command
4041
private $reader;
4142
private $extractor;
4243
private $defaultLocale;
44+
private $defaultTransPath;
45+
private $defaultViewsPath;
4346

44-
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale)
47+
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null)
4548
{
4649
parent::__construct();
4750

4851
$this->writer = $writer;
4952
$this->reader = $reader;
5053
$this->extractor = $extractor;
5154
$this->defaultLocale = $defaultLocale;
55+
$this->defaultTransPath = $defaultTransPath;
56+
$this->defaultViewsPath = $defaultViewsPath;
5257
}
5358

5459
/**
@@ -110,24 +115,39 @@ protected function execute(InputInterface $input, OutputInterface $output)
110115

111116
return 1;
112117
}
118+
/** @var KernelInterface $kernel */
113119
$kernel = $this->getApplication()->getKernel();
114120

115-
// Define Root Path to App folder
116-
$transPaths = array($kernel->getRootDir().'/Resources/');
121+
// Define Root Paths
122+
$transPaths = array($kernel->getRootDir().'/Resources/translations');
123+
if ($this->defaultTransPath) {
124+
$transPaths[] = $this->defaultTransPath;
125+
}
126+
$viewsPaths = array($kernel->getRootDir().'/Resources/views');
127+
if ($this->defaultViewsPath) {
128+
$viewsPaths[] = $this->defaultViewsPath;
129+
}
117130
$currentName = 'app folder';
118131

119132
// Override with provided Bundle info
120133
if (null !== $input->getArgument('bundle')) {
121134
try {
122135
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
123-
$transPaths = array(
124-
$foundBundle->getPath().'/Resources/',
125-
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()),
126-
);
136+
$transPaths = array($foundBundle->getPath().'/Resources/translations');
137+
if ($this->defaultTransPath) {
138+
$transPaths[] = $this->defaultTransPath.'/'.$foundBundle->getName();
139+
}
140+
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $foundBundle->getName());
141+
$viewsPaths = array($foundBundle->getPath().'/Resources/views');
142+
if ($this->defaultViewsPath) {
143+
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$foundBundle->getName();
144+
}
145+
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $foundBundle->getName());
127146
$currentName = $foundBundle->getName();
128147
} catch (\InvalidArgumentException $e) {
129148
// such a bundle does not exist, so treat the argument as path
130-
$transPaths = array($input->getArgument('bundle').'/Resources/');
149+
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
150+
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
131151
$currentName = $transPaths[0];
132152

133153
if (!is_dir($transPaths[0])) {
@@ -143,8 +163,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
143163
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
144164
$errorIo->comment('Parsing templates...');
145165
$this->extractor->setPrefix($input->getOption('prefix'));
146-
foreach ($transPaths as $path) {
147-
$path .= 'views';
166+
foreach ($viewsPaths as $path) {
148167
if (is_dir($path)) {
149168
$this->extractor->extract($path, $extractedCatalogue);
150169
}
@@ -154,7 +173,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
154173
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
155174
$errorIo->comment('Loading translation files...');
156175
foreach ($transPaths as $path) {
157-
$path .= 'translations';
158176
if (is_dir($path)) {
159177
$this->reader->read($path, $currentCatalogue);
160178
}
@@ -222,14 +240,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
222240

223241
$bundleTransPath = false;
224242
foreach ($transPaths as $path) {
225-
$path .= 'translations';
226243
if (is_dir($path)) {
227244
$bundleTransPath = $path;
228245
}
229246
}
230247

231248
if (!$bundleTransPath) {
232-
$bundleTransPath = end($transPaths).'translations';
249+
$bundleTransPath = end($transPaths);
233250
}
234251

235252
$this->writer->write($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->defaultLocale));

src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
<argument type="service" id="translator" />
7979
<argument type="service" id="translation.reader" />
8080
<argument type="service" id="translation.extractor" />
81+
<argument>%translator.default_path%</argument>
82+
<argument /> <!-- %twig.default_path% -->
8183
<tag name="console.command" command="debug:translation" />
8284
</service>
8385

@@ -86,6 +88,8 @@
8688
<argument type="service" id="translation.reader" />
8789
<argument type="service" id="translation.extractor" />
8890
<argument>%kernel.default_locale%</argument>
91+
<argument>%translator.default_path%</argument>
92+
<argument /> <!-- %twig.default_path% -->
8993
<tag name="console.command" command="translation:update" />
9094
</service>
9195

src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<service id="templating.helper.code" class="Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper">
5353
<tag name="templating.helper" alias="code" />
5454
<argument type="service" id="debug.file_link_formatter"></argument>
55-
<argument>%kernel.root_dir%</argument>
55+
<argument>%kernel.project_dir%</argument>
5656
<argument>%kernel.charset%</argument>
5757
</service>
5858

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ public function testDebugDefaultDirectory()
6464
$this->assertRegExp('/unused/', $tester->getDisplay());
6565
}
6666

67+
public function testDebugDefaultRootDirectory()
68+
{
69+
$this->fs->remove($this->translationDir);
70+
$this->fs = new Filesystem();
71+
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
72+
$this->fs->mkdir($this->translationDir.'/translations');
73+
$this->fs->mkdir($this->translationDir.'/templates');
74+
75+
$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'));
76+
$tester->execute(array('locale' => 'en'));
77+
78+
$this->assertRegExp('/missing/', $tester->getDisplay());
79+
$this->assertRegExp('/unused/', $tester->getDisplay());
80+
}
81+
6782
public function testDebugCustomDirectory()
6883
{
6984
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
@@ -100,6 +115,8 @@ protected function setUp()
100115
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
101116
$this->fs->mkdir($this->translationDir.'/Resources/translations');
102117
$this->fs->mkdir($this->translationDir.'/Resources/views');
118+
$this->fs->mkdir($this->translationDir.'/translations');
119+
$this->fs->mkdir($this->translationDir.'/templates');
103120
}
104121

105122
protected function tearDown()
@@ -174,7 +191,7 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
174191
->method('getContainer')
175192
->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock()));
176193

177-
$command = new TranslationDebugCommand($translator, $loader, $extractor);
194+
$command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates');
178195

179196
$application = new Application($kernel);
180197
$application->add($command);

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ public function testDumpMessagesAndClean()
3131
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
3232
}
3333

34+
public function testDumpMessagesAndCleanInRootDirectory()
35+
{
36+
$this->fs->remove($this->translationDir);
37+
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
38+
$this->fs->mkdir($this->translationDir.'/translations');
39+
$this->fs->mkdir($this->translationDir.'/templates');
40+
41+
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo')));
42+
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', '--dump-messages' => true, '--clean' => true));
43+
$this->assertRegExp('/foo/', $tester->getDisplay());
44+
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
45+
}
46+
3447
public function testDumpTwoMessagesAndClean()
3548
{
3649
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo', 'bar' => 'bar')));
@@ -55,6 +68,18 @@ public function testWriteMessages()
5568
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
5669
}
5770

71+
public function testWriteMessagesInRootDirectory()
72+
{
73+
$this->fs->remove($this->translationDir);
74+
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
75+
$this->fs->mkdir($this->translationDir.'/translations');
76+
$this->fs->mkdir($this->translationDir.'/templates');
77+
78+
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo')));
79+
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', '--force' => true));
80+
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
81+
}
82+
5883
public function testWriteMessagesForSpecificDomain()
5984
{
6085
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo'), 'mydomain' => array('bar' => 'bar')));
@@ -68,6 +93,8 @@ protected function setUp()
6893
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
6994
$this->fs->mkdir($this->translationDir.'/Resources/translations');
7095
$this->fs->mkdir($this->translationDir.'/Resources/views');
96+
$this->fs->mkdir($this->translationDir.'/translations');
97+
$this->fs->mkdir($this->translationDir.'/templates');
7198
}
7299

73100
protected function tearDown()
@@ -152,7 +179,7 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
152179
->method('getContainer')
153180
->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock()));
154181

155-
$command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en');
182+
$command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates');
156183

157184
$application = new Application($kernel);
158185
$application->add($command);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'enabled' => false,
2222
),
2323
'router' => array(
24-
'resource' => '%kernel.root_dir%/config/routing.xml',
24+
'resource' => '%kernel.project_dir%/config/routing.xml',
2525
'type' => 'xml',
2626
),
2727
'session' => array(
@@ -54,7 +54,7 @@
5454
'translator' => array(
5555
'enabled' => true,
5656
'fallback' => 'fr',
57-
'paths' => array('%kernel.root_dir%/Fixtures/translations'),
57+
'paths' => array('%kernel.project_dir%/Fixtures/translations'),
5858
),
5959
'validation' => array(
6060
'enabled' => true,

0 commit comments

Comments
 (0)
0