Skip to content

Commit 1085635

Browse files
Merge branch '3.4' into 4.0
* 3.4: [HttpKernel] reset kernel start time on reboot Add code of Conduct links in our README [DI] never inline lazy services bumped Symfony version to 3.4.12 updated VERSION for 3.4.11 updated CHANGELOG for 3.4.11 Default testsuite to latest PHPUnit 6.* [Github] Update the pull-request template bumped Symfony version to 2.8.42 updated VERSION for 2.8.41 updated CHANGELOG for 2.8.41 [HttpFoundation] Fix cookie test with xdebug [Serializer] Check the value of enable_max_depth if defined [DI] remove dead code [PhpUnitBridge] silence some stderr outputs [Validator] Update sl translation
2 parents 4b272d6 + b4b3ad5 commit 1085635

File tree

5 files changed

+112
-19
lines changed

5 files changed

+112
-19
lines changed

Compiler/InlineServiceDefinitionsPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ protected function processValue($value, $isRoot = false)
8888
*/
8989
private function isInlineableDefinition($id, Definition $definition, ServiceReferenceGraph $graph)
9090
{
91+
if ($definition->getErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic()) {
92+
return false;
93+
}
94+
9195
if (!$definition->isShared()) {
9296
return true;
9397
}
9498

95-
if ($definition->isDeprecated() || $definition->isPublic() || $definition->isLazy()) {
99+
if ($definition->isPublic()) {
96100
return false;
97101
}
98102

LazyProxy/ProxyHelper.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,4 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
5454
return $prefix.$parent->name;
5555
}
5656
}
57-
58-
private static function export($value)
59-
{
60-
if (!is_array($value)) {
61-
return var_export($value, true);
62-
}
63-
$code = array();
64-
foreach ($value as $k => $v) {
65-
$code[] = sprintf('%s => %s', var_export($k, true), self::export($v));
66-
}
67-
68-
return sprintf('array(%s)', implode(', ', $code));
69-
}
7057
}

Tests/Dumper/PhpDumperTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

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

14-
use DummyProxyDumper;
1514
use PHPUnit\Framework\TestCase;
1615
use Psr\Container\ContainerInterface;
1716
use Symfony\Component\Config\FileLocator;
@@ -488,6 +487,19 @@ public function testInlinedDefinitionReferencingServiceContainer()
488487
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
489488
}
490489

490+
public function testNonSharedLazyDefinitionReferences()
491+
{
492+
$container = new ContainerBuilder();
493+
$container->register('foo', 'stdClass')->setShared(false)->setLazy(true);
494+
$container->register('bar', 'stdClass')->addArgument(new Reference('foo', ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE, false))->setPublic(true);
495+
$container->compile();
496+
497+
$dumper = new PhpDumper($container);
498+
$dumper->setProxyDumper(new \DummyProxyDumper());
499+
500+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_non_shared_lazy.php', $dumper->dump());
501+
}
502+
491503
public function testInitializePropertiesBeforeMethodCalls()
492504
{
493505
require_once self::$fixturesPath.'/includes/classes.php';
@@ -556,7 +568,7 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
556568

557569
$dumper = new PhpDumper($container);
558570

559-
$dumper->setProxyDumper(new DummyProxyDumper());
571+
$dumper->setProxyDumper(new \DummyProxyDumper());
560572
$dumper->dump();
561573

562574
$this->addToAssertionCount(1);

Tests/Fixtures/includes/classes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ class DummyProxyDumper implements ProxyDumper
8585
{
8686
public function isProxyCandidate(Definition $definition)
8787
{
88-
return false;
88+
return $definition->isLazy();
8989
}
9090

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

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
/**
23+
* @internal but protected for BC on cache:clear
24+
*/
25+
protected $privates = array();
26+
27+
public function __construct()
28+
{
29+
$this->services = $this->privates = array();
30+
$this->methodMap = array(
31+
'bar' => 'getBarService',
32+
);
33+
34+
$this->aliases = array();
35+
}
36+
37+
public function reset()
38+
{
39+
$this->privates = array();
40+
parent::reset();
41+
}
42+
43+
public function compile()
44+
{
45+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
46+
}
47+
48+
public function isCompiled()
49+
{
50+
return true;
51+
}
52+
53+
public function getRemovedIds()
54+
{
55+
return array(
56+
'Psr\\Container\\ContainerInterface' => true,
57+
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
58+
'foo' => true,
59+
);
60+
}
61+
62+
protected function createProxy($class, \Closure $factory)
63+
{
64+
return $factory();
65+
}
66+
67+
/**
68+
* Gets the public 'bar' shared service.
69+
*
70+
* @return \stdClass
71+
*/
72+
protected function getBarService()
73+
{
74+
return $this->services['bar'] = new \stdClass($this->getFooService());
75+
}
76+
77+
/**
78+
* Gets the private 'foo' service.
79+
*
80+
* @return \stdClass
81+
*/
82+
protected function getFooService($lazyLoad = true)
83+
{
84+
// lazy factory
85+
86+
return new \stdClass();
87+
}
88+
}
89+
90+
// proxy code

0 commit comments

Comments
 (0)