Skip to content

Commit 988c7bd

Browse files
committed
Merge branch '3.2' into 3.3
* 3.2: [DI] Avoid private call to Container::has() Fixing missing abstract attribute in XmlDumper [Form] Remove DateTimeToStringTransformer $parseUsingPipe option Fix file perms Fixed filename in help text for update-data.php
2 parents da89b5d + 7e276d2 commit 988c7bd

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

Dumper/PhpDumper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,9 +1259,17 @@ private function getServiceConditionals($value)
12591259

12601260
$conditions = array();
12611261
foreach ($services as $service) {
1262+
if ($this->container->hasDefinition($service) && !$this->container->getDefinition($service)->isPublic()) {
1263+
continue;
1264+
}
1265+
12621266
$conditions[] = sprintf("\$this->has('%s')", $service);
12631267
}
12641268

1269+
if (!$conditions) {
1270+
return '';
1271+
}
1272+
12651273
return implode(' && ', $conditions);
12661274
}
12671275

Dumper/XmlDumper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ private function addService($definition, $id, \DOMElement $parent)
209209
$service->setAttribute('autoconfigure', 'true');
210210
}
211211

212+
if ($definition->isAbstract()) {
213+
$service->setAttribute('abstract', 'true');
214+
}
215+
212216
if ($callable = $definition->getConfigurator()) {
213217
$configurator = $this->document->createElement('configurator');
214218

Tests/Dumper/PhpDumperTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
2020
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
2121
use Symfony\Component\DependencyInjection\ContainerBuilder;
22+
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
2223
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
2324
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2425
use Symfony\Component\DependencyInjection\Reference;
@@ -605,4 +606,22 @@ public function testServiceSubscriber()
605606

606607
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_subscriber.php', $dumper->dump());
607608
}
609+
610+
public function testPrivateWithIgnoreOnInvalidReference()
611+
{
612+
require_once self::$fixturesPath.'/includes/classes.php';
613+
614+
$container = new ContainerBuilder();
615+
$container->register('not_invalid', 'BazClass')
616+
->setPublic(false);
617+
$container->register('bar', 'BarClass')
618+
->addMethodCall('setBaz', array(new Reference('not_invalid', SymfonyContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
619+
$container->compile();
620+
621+
$dumper = new PhpDumper($container);
622+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference')));
623+
624+
$container = new \Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference();
625+
$this->assertInstanceOf('BazClass', $container->get('bar')->getBaz());
626+
}
608627
}

Tests/Dumper/XmlDumperTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,12 @@ public function testDumpAutowireData()
183183

184184
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services24.xml'), $dumper->dump());
185185
}
186+
187+
public function testDumpAbstractServices()
188+
{
189+
$container = include self::$fixturesPath.'/containers/container_abstract.php';
190+
$dumper = new XmlDumper($container);
191+
192+
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services_abstract.xml'), $dumper->dump());
193+
}
186194
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerBuilder;
4+
5+
$container = new ContainerBuilder();
6+
7+
$container
8+
->register('foo', 'Foo')
9+
->setAbstract(true)
10+
;
11+
12+
return $container;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" synthetic="true"/>
5+
<service id="foo" class="Foo" abstract="true"/>
6+
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false"/>
7+
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false"/>
8+
</services>
9+
</container>

0 commit comments

Comments
 (0)