8000 [DI] fix dumping setters before their inlined instances by nicolas-grekas · Pull Request #28678 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] fix dumping setters before their inlined instances #28678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
8000 Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[DI] fix dumping setters before their inlined instances
  • Loading branch information
nicolas-grekas committed Oct 2, 2018
commit d60eb1aa338d6a0ff98c43e8f27de28dc634cf62
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,9 @@ private function addInlineService(&$head, &$tail, $id, Definition $definition, $

$code = '';
$arguments = array($definition->getProperties(), $definition->getMethodCalls(), $definition->getConfigurator());
$hasSelfRef = $this->addInlineVariables($code, $tail, $id, $arguments, false) || $hasSelfRef;
$hasSelfRef = $this->addInlineVariables($code, $code, $id, $arguments, false) || $hasSelfRef;

$code .= '' !== $code ? "\n" : '';
$code .= $this->addServiceProperties($definition, $name);
$code .= $this->addServiceMethodCalls($definition, $name);
$code .= $this->addServiceConfigurator($definition, $name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ protected function getFooService()
$b = new \stdClass();
$c = new \stdClass();
$c->p3 = new \stdClass();

$b->p2 = $c;

return $this->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\FooForDeepGraph($a, $b);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;

/**
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*
* @final since Symfony 3.3
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();

public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'tsantos\\serializer\\serializerinterface' => 'TSantos\\Serializer\\SerializerInterface',
);
$this->methodMap = array(
'tsantos_serializer' => 'getTsantosSerializerService',
);
$this->aliases = array(
'TSantos\\Serializer\\SerializerInterface' => 'tsantos_serializer',
);
}

public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}

public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
}

public function isCompiled()
{
return true;
}

public function isFrozen()
{
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED);

return true;
}

/**
* Gets the public 'tsantos_serializer' shared service.
*
* @return \TSantos\Serializer\EventEmitterSerializer
*/
protected function getTsantosSerializerService()
{
$a = new \TSantos\Serializer\NormalizerRegistry();

$d = new \TSantos\Serializer\EventDispatcher\EventDispatcher();
$d->addSubscriber(new \TSantos\SerializerBundle\EventListener\StopwatchListener(new \Symfony\Component\Stopwatch\Stopwatch(true)));

$this->services['tsantos_serializer'] = $instance = new \TSantos\Serializer\EventEmitterSerializer(new \TSantos\Serializer\Encoder\JsonEncoder(), $a, $d);

$b = new \TSantos\Serializer\Normalizer\CollectionNormalizer();

$b->setSerializer($instance);

$c = new \TSantos\Serializer\Normalizer\JsonNormalizer();

$c->setSerializer($instance);

$a->add(new \TSantos\Serializer\Normalizer\ObjectNormalizer(new \TSantos\SerializerBundle\Serializer\CircularReferenceHandler()));
$a->add($b);
$a->add($c);

return $instance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<services>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
<service id="tsantos_serializer" class="TSantos\Serializer\EventEmitterSerializer" public="true">
<argument type="service">
<service class="TSantos\Serializer\Encoder\JsonEncoder" public="false">
<tag name="tsantos_serializer.encoder" format="json"/>
</service>
</argument>
<argument type="service">
<service class="TSantos\Serializer\NormalizerRegistry" public="false">
<call method="add">
<argument type="service">
<service class="TSantos\Serializer\Normalizer\ObjectNormalizer" public="false">
<tag name="tsantos_serializer.normalizer" priority="-800"/>
<argument type="service">
<service class="TSantos\SerializerBundle\Serializer\CircularReferenceHandler" public="false"/>
</argument>
</service>
</argument>
</call>
<call method="add">
<argument type="service">
<service class="TSantos\Serializer\Normalizer\CollectionNormalizer" public="false">
<tag name="tsantos_serializer.normalizer" priority="-900"/>
<call method="setSerializer">
<argument type="service" id="tsantos_serializer"/>
</call>
</service>
</argument>
</call>
<call method="add">
<argument type="service">
<service class="TSantos\Serializer\Normalizer\JsonNormalizer" public="false">
<tag name="tsantos_serializer.normalizer" priority="-1000"/>
<call method="setSerializer">
<argument type="service" id="tsantos_serializer"/>
</call>
</service>
</argument>
</call>
</service>
</argument>
<argument type="service">
<service class="TSantos\Serializer\EventDispatcher\EventDispatcher" public="false">
<call method="addSubscriber">
<argument type="service">
<service class="TSantos\SerializerBundle\EventListener\StopwatchListener" public="false">
<tag name="tsantos_serializer.event_subscriber"/>
<argument type="service">
<service class="Symfony\Component\Stopwatch\Stopwatch" public="false">
<tag name="kernel.reset" method="reset"/>
<argument>true</argument>
</service>
</argument>
</service>
</argument>
</call>
</service>
</argument>
</service>
<service id="TSantos\Serializer\SerializerInterface" alias="tsantos_serializer" public="true"/>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand Down Expand Up @@ -807,4 +808,16 @@ public function testBindings()
'$factory' => 'factory',
), array_map(function ($v) { return $v->getValues()[0]; }, $definition->getBindings()));
}

public function testTsantosContainer()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services_tsantos.xml');
$container->compile();

$dumper = new PhpDumper($container);
$dump = $dumper->dump();
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_tsantos.php', $dumper->dump());
}
}
0