Skip to content

Commit c001098

Browse files
Merge branch '4.1'
* 4.1: (26 commits) Revert "bug #27312 Supress deprecation notices thrown when getting private servies from container in tests (arderyp)" [HttpKernel] reset kernel start time on reboot Add code of Conduct links in our README bumped Symfony version to 4.0.12 [FrameworkBundle] Fix using test.service_container when Client is rebooted [DI] never inline lazy services updated VERSION for 4.0.11 updated CHANGELOG for 4.0.11 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 Tweak Argon2 test config [HttpFoundation] Fix cookie test with xdebug [FrameworkBundle] cleanup generated test container [Serializer] Check the value of enable_max_depth if defined ...
2 parents 974257d + f2a3f0d commit c001098

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() || $definition->getErrors()) {
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;
@@ -530,6 +529,19 @@ public function testInlinedDefinitionReferencingServiceContainer()
530529
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
531530
}
532531

532+
public function testNonSharedLazyDefinitionReferences()
533+
{
534+
$container = new ContainerBuilder();
535+
$container->register('foo', 'stdClass')->setShared(false)->setLazy(true);
536+
$container->register('bar', 'stdClass')->addArgument(new Reference('foo', ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE, false))->setPublic(true);
537+
$container->compile();
538+
539+
$dumper = new PhpDumper($container);
540+
$dumper->setProxyDumper(new \DummyProxyDumper());
541+
542+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_non_shared_lazy.php', $dumper->dump());
543+
}
544+
533545
public function testInitializePropertiesBeforeMethodCalls()
534546
{
535547
require_once self::$fixturesPath.'/includes/classes.php';
@@ -598,7 +610,7 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
598610

599611
$dumper = new PhpDumper($container);
600612

601-
$dumper->setProxyDumper(new DummyProxyDumper());
613+
$dumper->setProxyDumper(new \DummyProxyDumper());
602614
$dumper->dump();
603615

604616
$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)