Skip to content

Commit b0a3a85

Browse files
Merge branch '3.0'
* 3.0: (105 commits) [Console] remove readline support bumped Symfony version to 3.0.3 updated VERSION for 3.0.2 updated CHANGELOG for 3.0.2 [Routing] added a suggestion to add the HttpFoundation component. [FrameworkBundle] fix assets and templating tests [ClassLoader] fix ApcClassLoader tests on HHVM [travis] Add some comments changed operator from and to && [DependencyInjection] Remove unused parameter [Process] Fix transient tests for incremental outputs [Console] Add missing `@require` annotation in test Fix merge [appveyor] Fix failure reporting [#17634] move DebugBundle license file Limit Ldap component version for the 3.0 branch backport GlobTest from 2.7 branch Move licenses according to new best practices [FrameworkBundle] Remove unused code in test [2.3] Fixed an undefined variable in Glob::toRegex ... Conflicts: .travis.yml composer.json src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_item.html.twig src/Symfony/Component/Console/CHANGELOG.md src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/PropertyInfo/Tests/PropertyInfoExtractorTest.php src/Symfony/Component/Yaml/Tests/ParserTest.php
2 parents 46008af + 7f2ec17 commit b0a3a85

13 files changed

+130
-7
lines changed

Compiler/InlineServiceDefinitionsPass.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function inlineArguments(ContainerBuilder $container, array $arguments,
7272
continue;
7373
}
7474

75-
if ($this->isInlineableDefinition($container, $id, $definition = $container->getDefinition($id))) {
75+
if ($this->isInlineableDefinition($id, $definition = $container->getDefinition($id))) {
7676
$this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId));
7777

7878
if ($definition->isShared()) {
@@ -100,13 +100,12 @@ private function inlineArguments(ContainerBuilder $container, array $arguments,
100100
/**
101101
* Checks if the definition is inlineable.
102102
*
103-
* @param ContainerBuilder $container
104-
* @param string $id
105-
* @param Definition $definition
103+
* @param string $id
104+
* @param Definition $definition
106105
*
107106
* @return bool If the definition is inlineable
108107
*/
109-
private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition)
108+
private function isInlineableDefinition($id, Definition $definition)
110109
{
111110
if (!$definition->isShared()) {
112111
return true;

Compiler/ResolveReferencesToAliasesPass.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Definition;
1516
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
1617
use Symfony\Component\DependencyInjection\Reference;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -42,6 +43,7 @@ public function process(ContainerBuilder $container)
4243
$definition->setArguments($this->processArguments($definition->getArguments()));
4344
$definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
4445
$definition->setProperties($this->processArguments($definition->getProperties()));
46+
$definition->setFactory($this->processFactory($definition->getFactory()));
4547
}
4648

4749
foreach ($container->getAliases() as $id => $alias) {
@@ -76,6 +78,21 @@ private function processArguments(array $arguments)
7678
return $arguments;
7779
}
7880

81+
private function processFactory($factory)
82+
{
83+
if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) {
84+
return $factory;
85+
}
86+
87+
$defId = $this->getDefinitionId($id = (string) $factory[0]);
88+
89+
if ($defId !== $id) {
90+
$factory[0] = new Reference($defId, $factory[0]->getInvalidBehavior());
91+
}
92+
93+
return $factory;
94+
}
95+
7996
/**
8097
* Resolves an alias into a definition id.
8198
*

Loader/XmlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ private function parseDefinition(\DOMElement $service, $file)
228228
$parameters[$name] = XmlUtils::phpize($node->nodeValue);
229229
}
230230

231+
if ('' === $tag->getAttribute('name')) {
232+
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', (string) $service->getAttribute('id'), $file));
233+
}
234+
231235
$definition->addTag($tag->getAttribute('name'), $parameters);
232236
}
233237

Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ private function parseDefinition($id, $service, $file)
286286
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
287287
}
288288

289+
if (!is_string($tag['name']) || '' === $tag['name']) {
290+
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
291+
}
292+
289293
$name = $tag['name'];
290294
unset($tag['name']);
291295

Loader/schema/dic/services/services-1.0.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
</xsd:complexType>
104104

105105
<xsd:complexType name="tag">
106-
<xsd:attribute name="name" type="xsd:string" />
106+
<xsd:attribute name="name" type="xsd:string" use="required" />
107107
<xsd:anyAttribute namespace="##any" processContents="lax" />
108108
</xsd:complexType>
109109

Tests/Compiler/ExtensionCompilerPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ExtensionCompilerPassTest extends \PHPUnit_Framework_TestCase
2121
private $container;
2222
private $pass;
2323

24-
public function setUp()
24+
protected function setUp()
2525
{
2626
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
2727
$this->pass = new ExtensionCompilerPass();

Tests/Compiler/ResolveReferencesToAliasesPassTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Definition;
1416
use Symfony\Component\DependencyInjection\Reference;
1517
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
1618
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -59,6 +61,27 @@ public function testAliasCircularReference()
5961
$this->process($container);
6062
}
6163

64+
public function testResolveFactory()
65+
{
66+
$container = new ContainerBuilder();
67+
$container->register('factory', 'Factory');
68+
$container->setAlias('factory_alias', new Alias('factory'));
69+
$foo = new Definition();
70+
$foo->setFactory(array(new Reference('factory_alias'), 'createFoo'));
71+
$container->setDefinition('foo', $foo);
72+
$bar = new Definition();
73+
$bar->setFactory(array('Factory', 'createFoo'));
74+
$container->setDefinition('bar', $bar);
75+
76+
$this->process($container);
77+
78+
$resolvedFooFactory = $container->getDefinition('foo')->getFactory();
79+
$resolvedBarFactory = $container->getDefinition('bar')->getFactory();
80+
81+
$this->assertSame('factory', (string) $resolvedFooFactory[0]);
82+
$this->assertSame('Factory', (string) $resolvedBarFactory[0]);
83+
}
84+
6285
protected function process(ContainerBuilder $container)
6386
{
6487
$pass = new ResolveReferencesToAliasesPass();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="foo" class="BarClass">
8+
<tag name="" foo="bar" />
9+
</service>
10+
</services>
11+
</container>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="foo" class="BarClass">
8+
<tag foo="bar" />
9+
</service>
10+
</services>
11+
</container>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
foo_service:
3+
class: FooClass
4+
tags:
5+
# tag name is an empty string
6+
- { name: '', foo: bar }

0 commit comments

Comments
 (0)