Skip to content

Commit 320cf40

Browse files
[DI] Fix resetting private services
1 parent c431fd9 commit 320cf40

17 files changed

+159
-1
lines changed

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use ProxyManager\Generator\ClassGenerator;
1515
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
1616
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
1920

@@ -69,7 +70,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $methodName = n
6970
$instantiation = 'return';
7071

7172
if ($definition->isShared()) {
72-
$instantiation .= " \$this->services['$id'] =";
73+
$instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() || !method_exists(ContainerBuilder::class, 'addClassResource') ? 'services' : 'privates', $id);
7374
}
7475

7576
if (null === $methodName) {

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

+22
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function dump(array $options = array())
153153
$code =
154154
$this->startClass($options['class'], $options['base_class'], $options['namespace']).
155155
$this->addConstructor().
156+
$this->addReset().
156157
$this->addCompile().
157158
$this->addIsCompiled().
158159
$this->addServices().
@@ -831,6 +832,27 @@ public function __construct()
831832
return $code;
832833
}
833834

835+
/**
836+
* Adds the reset method for a compiled container.
837+
*
838+
* @return string
839+
*/
840+
private function addReset()
841+
{
842+
return <<<EOF
843+
844+
/*{$this->docStar}
845+
* {@inheritdoc}
846+
*/
847+
public function reset()
848+
{
849+
\$this->privates = array();
850+
parent::reset();
851+
}
852+
853+
EOF;
854+
}
855+
834856
/**
835857
* Adds the compile method for a compiled container.
836858
*

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public function __construct()
3434
$this->aliases = array();
3535
}
3636

37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function reset()
41+
{
42+
$this->privates = array();
43+
parent::reset();
44+
}
45+
3746
/**
3847
* {@inheritdoc}
3948
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public function __construct()
3232
$this->aliases = array();
3333
}
3434

35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function reset()
39+
{
40+
$this->privates = array();
41+
parent::reset();
42+
}
43+
3544
/**
3645
* {@inheritdoc}
3746
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public function __construct()
3737
$this->aliases = array();
3838
}
3939

40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function reset()
44+
{
45+
$this->privates = array();
46+
parent::reset();
47+
}
48+
4049
/**
4150
* {@inheritdoc}
4251
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public function __construct()
4141
$this->aliases = array();
4242
}
4343

44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function reset()
48+
{
49+
$this->privates = array();
50+
parent::reset();
51+
}
52+
4453
/**
4554
* {@inheritdoc}
4655
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public function __construct()
3535
$this->aliases = array();
3636
}
3737

38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function reset()
42+
{
43+
$this->privates = array();
44+
parent::reset();
45+
}
46+
3847
/**
3948
* {@inheritdoc}
4049
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function __construct()
3636
$this->aliases = array();
3737
}
3838

39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function reset()
43+
{
44+
$this->privates = array();
45+
parent::reset();
46+
}
47+
3948
/**
4049
* {@inheritdoc}
4150
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public function __construct()
3535
$this->aliases = array();
3636
}
3737

38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function reset()
42+
{
43+
$this->privates = array();
44+
parent::reset();
45+
}
46+
3847
/**
3948
* {@inheritdoc}
4049
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public function __construct()
3737
$this->aliases = array();
3838
}
3939

40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function reset()
44+
{
45+
$this->privates = array();
46+
parent::reset();
47+
}
48+
4049
/**
4150
* {@inheritdoc}
4251
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public function __construct()
3535
$this->aliases = array();
3636
}
3737

38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function reset()
42+
{
43+
$this->privates = array();
44+
parent::reset();
45+
}
46+
3847
/**
3948
* {@inheritdoc}
4049
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public function __construct()
3434
$this->aliases = array();
3535
}
3636

37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function reset()
41+
{
42+
$this->privates = array();
43+
parent::reset();
44+
}
45+
3746
/**
3847
* {@inheritdoc}
3948
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public function __construct()
6060
);
6161
}
6262

63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function reset()
67+
{
68+
$this->privates = array();
69+
parent::reset();
70+
}
71+
6372
/**
6473
* {@inheritdoc}
6574
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public function __construct()
4141
$this->aliases = array();
4242
}
4343

44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function reset()
48+
{
49+
$this->privates = array();
50+
parent::reset();
51+
}
52+
4453
/**
4554
* {@inheritdoc}
4655
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public function __construct()
4242
$this->aliases = array();
4343
}
4444

45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function reset()
49+
{
50+
$this->privates = array();
51+
parent::reset();
52+
}
53+
4554
/**
4655
* {@inheritdoc}
4756
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function __construct()
3636
$this->aliases = array();
3737
}
3838

39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function reset()
43+
{
44+
$this->privates = array();
45+
parent::reset();
46+
}
47+
3948
/**
4049
* {@inheritdoc}
4150
*/

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function __construct()
3636
$this->aliases = array();
3737
}
3838

39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function reset()
43+
{
44+
$this->privates = array();
45+
parent::reset();
46+
}
47+
3948
/**
4049
* {@inheritdoc}
4150
*/

0 commit comments

Comments
 (0)