Skip to content

Commit 5832e08

Browse files
Merge branch '3.4' into 4.0
* 3.4: fixed CS Avoiding session migration for stateless firewall UsernamePasswordJsonAuthenticationListener fixed CS Avoid migration on stateless firewalls [Serializer] deserialize from xml: Fix a collection that contains the only one element [PhpUnitBridge] Fix error on some Windows OS [DI] Deduplicate generated proxy classes
2 parents 1085635 + 922bd54 commit 5832e08

File tree

5 files changed

+111
-5
lines changed

5 files changed

+111
-5
lines changed

Dumper/PhpDumper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ private function collectLineage($class, array &$lineage)
397397

398398
private function generateProxyClasses()
399399
{
400+
$alreadyGenerated = array();
400401
$definitions = $this->container->getDefinitions();
401402
$strip = '' === $this->docStar && method_exists('Symfony\Component\HttpKernel\Kernel', 'stripComments');
402403
$proxyDumper = $this->getProxyDumper();
@@ -405,8 +406,12 @@ private function generateProxyClasses()
405406
if (!$proxyDumper->isProxyCandidate($definition)) {
406407
continue;
407408
}
409+
if (isset($alreadyGenerated[$class = $definition->getClass()])) {
410+
continue;
411+
}
412+
$alreadyGenerated[$class] = true;
408413
// register class' reflector for resource tracking
409-
$this->container->getReflectionClass($definition->getClass());
414+
$this->container->getReflectionClass($class);
410415
$proxyCode = "\n".$proxyDumper->getProxyCode($definition);
411416
if ($strip) {
412417
$proxyCode = "<?php\n".$proxyCode;

Tests/Dumper/PhpDumperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,19 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
574574
$this->addToAssertionCount(1);
575575
}
576576

577+
public function testDedupLazyProxy()
578+
{
579+
$container = new ContainerBuilder();
580+
$container->register('foo', 'stdClass')->setLazy(true)->setPublic(true);
581+
$container->register('bar', 'stdClass')->setLazy(true)->setPublic(true);
582+
$container->compile();
583+
584+
$dumper = new PhpDumper($container);
585+
$dumper->setProxyDumper(new \DummyProxyDumper());
586+
587+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_dedup_lazy_proxy.php', $dumper->dump());
588+
}
589+
577590
public function testLazyArgumentProvideGenerator()
578591
{
579592
require_once self::$fixturesPath.'/includes/classes.php';

Tests/Fixtures/includes/classes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ public function isProxyCandidate(Definition $definition)
9090

9191
public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null)
9292
{
93-
return " // lazy factory\n\n";
93+
return " // lazy factory for {$definition->getClass()}\n\n";
9494
}
9595

9696
public function getProxyCode(Definition $definition)
9797
{
98-
return "// proxy code\n";
98+
return "// proxy code for {$definition->getClass()}\n";
9999
}
100100
}
101101

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
4+
use Symfony\Component\DependencyInjection\ContainerInterface;
5+
use Symfony\Component\DependencyInjection\Container;
6+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7+
use Symfony\Component\DependencyInjection\Exception\LogicException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
11+
/**
12+
* This class has been auto-generated
13+
* by the Symfony Dependency Injection Component.
14+
*
15+
* @final since Symfony 3.3
16+
*/
17+
class ProjectServiceContainer extends Container
18+
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
22+
public function __construct()
23+
{
24+
$this->services = array();
25+
$this->methodMap = array(
26+
'bar' => 'getBarService',
27+
'foo' => 'getFooService',
28+
);
29+
30+
$this->aliases = array();
31+
}
32+
33+
public function getRemovedIds()
34+
{
35+
return array(
36+
'Psr\\Container\\ContainerInterface' => true,
37+
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
38+
);
39+
}
40+
41+
public function compile()
42+
{
43+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
44+
}
45+
46+
public function isCompiled()
47+
{
48+
return true;
49+
}
50+
51+
public function isFrozen()
52+
{
53+
@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);
54+
55+
return true;
56+
}
57+
58+
protected function createProxy($class, \Closure $factory)
59+
{
60+
return $factory();
61+
}
62+
63+
/**
64+
* Gets the public 'bar' shared service.
65+
*
66+
* @return \stdClass
67+
*/
68+
protected function getBarService($lazyLoad = true)
69+
{
70+
// lazy factory for stdClass
71+
72+
return new \stdClass();
73+
}
74+
75+
/**
76+
* Gets the public 'foo' shared service.
77+
*
78+
* @return \stdClass
79+
*/
80+
protected function getFooService($lazyLoad = true)
81+
{
82+
// lazy factory for stdClass
83+
84+
return new \stdClass();
85+
}
86+
}
87+
88+
// proxy code for stdClass

Tests/Fixtures/php/services_non_shared_lazy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ protected function getBarService()
8181
*/
8282
protected function getFooService($lazyLoad = true)
8383
{
84-
// lazy factory
84+
// lazy factory for stdClass
8585

8686
return new \stdClass();
8787
}
8888
}
8989

90-
// proxy code
90+
// proxy code for stdClass

0 commit comments

Comments
 (0)