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

Skip to content

Commit ed1500f

Browse files
Merge branch '3.4' into 4.1
* 3.4: [Twig] Replace for-loops with blocks for attributes [DI] fix reporting bindings on overriden services as unused
2 parents 34274d4 + 44e9a91 commit ed1500f

File tree

11 files changed

+73
-21
lines changed

11 files changed

+73
-21
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
{% set label = name|humanize %}
9999
{%- endif -%}
100100
{%- endif -%}
101-
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
101+
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
102102
{{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
103103
</label>
104104
{%- endif -%}

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
{%- endif -%}
261261

262262
{{ widget|raw }}
263-
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
263+
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
264264
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
265265
{{- form_errors(form) -}}
266266
</label>

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
{%- else -%}
351351
{% set form_method = "POST" %}
352352
{%- endif -%}
353-
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
353+
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
354354
{%- if form_method != method -%}
355355
<input type="hidden" name="_method" value="{{ method }}" />
356356
{%- endif -%}

src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
{% set label = name|humanize %}
259259
{%- endif -%}
260260
{% endif %}
261-
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
261+
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
262262
{{ widget|raw }}
263263
{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}
264264
</label>

src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class ResolveBindingsPass extends AbstractRecursivePass
3434
*/
3535
public function process(ContainerBuilder $container)
3636
{
37+
$this->usedBindings = $container->getRemovedBindingIds();
38+
3739
try {
3840
parent::process($container);
3941

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
122122

123123
private $removedIds = array();
124124

125+
private $removedBindingIds = array();
126+
125127
private static $internalTypes = array(
126128
'int' => true,
127129
'float' => true,
@@ -498,7 +500,8 @@ public function set($id, $service)
498500
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
499501
}
500502

501-
unset($this->definitions[$id], $this->aliasDefinitions[$id], $this->removedIds[$id]);
503+
$this->removeId($id);
504+
unset($this->removedIds[$id]);
502505

503506
parent::set($id, $service);
504507
}
@@ -511,8 +514,7 @@ public function set($id, $service)
511514
public function removeDefinition($id)
512515
{
513516
if (isset($this->definitions[$id = (string) $id])) {
514-
unset($this->definitions[$id]);
515-
$this->removedIds[$id] = true;
517+
$this->removeId($id);
516518
}
517519
}
518520

@@ -834,7 +836,8 @@ public function setAlias($alias, $id)
834836
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
835837
}
836838

837-
unset($this->definitions[$alias], $this->removedIds[$alias]);
839+
$this->removeId($alias);
840+
unset($this->removedIds[$alias]);
838841

839842
return $this->aliasDefinitions[$alias] = $id;
840843
}
@@ -847,8 +850,7 @@ public function setAlias($alias, $id)
847850
public function removeAlias($alias)
848851
{
849852
if (isset($this->aliasDefinitions[$alias = (string) $alias])) {
850-
unset($this->aliasDefinitions[$alias]);
851-
$this->removedIds[$alias] = true;
853+
$this->removeId($alias);
852854
}
853855
}
854856

@@ -977,7 +979,8 @@ public function setDefinition($id, Definition $definition)
977979

978980
$id = (string) $id;
979981

980-
unset($this->aliasDefinitions[$id], $this->removedIds[$id]);
982+
$this->removeId($id);
983+
unset($this->removedIds[$id]);
981984

982985
return $this->definitions[$id] = $definition;
983986
}
@@ -1479,6 +1482,18 @@ public static function getInitializedConditionals($value)
14791482
return $services;
14801483
}
14811484

1485+
/**
1486+
* Gets removed binding ids.
1487+
*
1488+
* @return array
1489+
*
1490+
* @internal
1491+
*/
1492+
public function getRemovedBindingIds()
1493+
{
1494+
return $this->removedBindingIds;
1495+
}
1496+
14821497
/**
14831498
* Computes a reasonably unique hash of a value.
14841499
*
@@ -1583,4 +1598,21 @@ private function inVendors($path)
15831598

15841599
return false;
15851600
}
1601+
1602+
private function removeId($id)
1603+
{
1604+
$this->removedIds[$id] = true;
1605+
unset($this->aliasDefinitions[$id]);
1606+
1607+
if (!isset($this->definitions[$id])) {
1608+
return;
1609+
}
1610+
1611+
foreach ($this->definitions[$id]->getBindings() as $binding) {
1612+
list(, $identifier) = $binding->getValues();
1613+
$this->removedBindingIds[$identifier] = true;
1614+
}
1615+
1616+
unset($this->definitions[$id]);
1617+
}
15861618
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,22 @@ public function testScalarSetter()
111111

112112
$this->assertEquals(array(array('setDefaultLocale', array('fr'))), $definition->getMethodCalls());
113113
}
114+
115+
public function testOverriddenBindings()
116+
{
117+
$container = new ContainerBuilder();
118+
119+
$binding = new BoundArgument('bar');
120+
121+
$container->register('foo', 'stdClass')
122+
->setBindings(array('$foo' => clone $binding));
123+
$container->register('bar', 'stdClass')
124+
->setBindings(array('$foo' => clone $binding));
125+
126+
$container->register('foo', 'stdClass');
127+
128+
(new ResolveBindingsPass())->process($container);
129+
130+
$this->assertInstanceOf('stdClass', $container->get('foo'));
131+
}
114132
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ protected function process(ContainerBuilder $container)
399399

400400
/**
401401
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
402-
* @expectedExceptionMessageRegExp /^Circular reference detected for service "c", path: "c -> b -> a -> c"./
402+
* @expectedExceptionMessageRegExp /^Circular reference detected for service "a", path: "a -> c -> b -> a"./
403403
*/
404404
public function testProcessDetectsChildDefinitionIndirectCircularReference()
405405
{

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ public function testMerge()
559559
$config->setDefinition('baz', new Definition('BazClass'));
560560
$config->setAlias('alias_for_foo', 'foo');
561561
$container->merge($config);
562-
$this->assertEquals(array('service_container', 'foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
562+
$this->assertEquals(array('foo', 'bar', 'service_container', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
563563

564564
$aliases = $container->getAliases();
565565
$this->assertArrayHasKey('alias_for_foo', $aliases);

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/instanceof.expected.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ services:
44
class: Symfony\Component\DependencyInjection\ContainerInterface
55
public: true
66
synthetic: true
7+
foo:
8+
class: App\FooService
9+
public: true
710
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
811
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
912
public: true
@@ -16,6 +19,3 @@ services:
1619

1720
shared: false
1821
configurator: c
19-
foo:
20-
class: App\FooService
21-
public: true

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.expected.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ services:
44
class: Symfony\Component\DependencyInjection\ContainerInterface
55
public: true
66
synthetic: true
7-
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
8-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
7+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
8+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
99
public: true
1010
tags:
1111
- { name: foo }
1212
- { name: baz }
1313
deprecated: '%service_id%'
14+
lazy: true
1415
arguments: [1]
1516
factory: f
16-
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar:
17-
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar
17+
Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo:
18+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
1819
public: true
1920
tags:
2021
- { name: foo }
2122
- { name: baz }
2223
deprecated: '%service_id%'
23-
lazy: true
2424
arguments: [1]
2525
factory: f

0 commit comments

Comments
 (0)
0