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 4cbb3fd

Browse filesBrowse files
committed
Merge branch '2.7' into 2.8
* 2.7: Validate XLIFF translation files [DependencyInjection] replace alias in factories replace alias in factory services
2 parents ddc8ece + 6190058 commit 4cbb3fd
Copy full SHA for 4cbb3fd

File tree

Expand file treeCollapse file tree

5 files changed

+129
-1
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+129
-1
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ private function updateReferences($container, $currentId, $newId)
9595
$definition->setProperties(
9696
$this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
9797
);
98+
99+
$definition->setFactoryService($this->updateFactoryServiceReference($definition->getFactoryService(), $currentId, $newId));
100+
$definition->setFactory($this->updateFactoryReference($definition->getFactory(), $currentId, $newId));
98101
}
99102
}
100103

@@ -122,4 +125,26 @@ private function updateArgumentReferences(array $arguments, $currentId, $newId)
122125

123126
return $arguments;
124127
}
128+
129+
private function updateFactoryServiceReference($factoryService, $currentId, $newId)
130+
{
131+
if (null === $factoryService) {
132+
return;
133+
}
134+
135+
return $currentId === $factoryService ? $newId : $currentId;
136+
}
137+
138+
private function updateFactoryReference($factory, $currentId, $newId)
139+
{
140+
if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) {
141+
return $factory;
142+
}
143+
144+
if ($currentId === (string) $factory[0]) {
145+
$factory[0] = new Reference($newId, $factory[0]->getInvalidBehavior());
146+
}
147+
148+
return $factory;
149+
}
125150
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414
use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\Reference;
1718

1819
class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
1920
{
2021
public function testProcess()
2122
{
2223
$container = new ContainerBuilder();
2324

24-
$container->register('a', '\stdClass');
25+
$aDefinition = $container->register('a', '\stdClass');
26+
$aDefinition->setFactoryService('b');
27+
$aDefinition->setFactoryMethod('createA');
28+
29+
$aDefinition->setFactory(array(new Reference('b'), 'createA'));
2530

2631
$bDefinition = new Definition('\stdClass');
2732
$bDefinition->setPublic(false);
@@ -39,6 +44,11 @@ public function testProcess()
3944
$container->has('b_alias') && !$container->hasAlias('b_alias'),
4045
'->process() replaces alias to actual.'
4146
);
47+
48+
$this->assertSame('b_alias', $aDefinition->getFactoryService());
49+
50+
$resolvedFactory = $aDefinition->getFactory();
51+
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
4252
}
4353

4454
/**
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Component\Form\Tests\Resources;
13+
14+
class TranslationFilesTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @dataProvider provideTranslationFiles
18+
*/
19+
public function testTranslationFileIsValid($filePath)
20+
{
21+
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
22+
}
23+
24+
public function provideTranslationFiles()
25+
{
26+
return array_map(
27+
function ($filePath) { return (array) $filePath; },
28+
glob(dirname(dirname(__DIR__)).'/Resources/translations/*.xlf')
29+
);
30+
}
31+
}
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Component\Security\Tests\Resources;
13+
14+
class TranslationFilesTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @dataProvider provideTranslationFiles
18+
*/
19+
public function testTranslationFileIsValid($filePath)
20+
{
21+
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
22+
}
23+
24+
public function provideTranslationFiles()
25+
{
26+
return array_map(
27+
function ($filePath) { return (array) $filePath; },
28+
glob(dirname(dirname(__DIR__)).'/Resources/translations/*.xlf')
29+
);
30+
}
31+
}
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Component\Validator\Tests\Resources;
13+
14+
class TranslationFilesTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @dataProvider provideTranslationFiles
18+
*/
19+
public function testTranslationFileIsValid($filePath)
20+
{
21+
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
22+
}
23+
24+
public function provideTranslationFiles()
25+
{
26+
return array_map(
27+
function ($filePath) { return (array) $filePath; },
28+
glob(dirname(dirname(__DIR__)).'/Resources/translations/*.xlf')
29+
);
30+
}
31+
}

0 commit comments

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