Skip to content

[DI] Fix resetting private services #23645

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
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ProxyManager\Generator\ClassGenerator;
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;

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

if ($definition->isShared()) {
$instantiation .= " \$this->services['$id'] =";
$instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() || !method_exists(ContainerBuilder::class, 'addClassResource') ? 'services' : 'privates', $id);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also missed updating ProxyDumper, now fixed

}

if (null === $methodName) {
Expand Down
22 changes: 22 additions & 0 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function dump(array $options = array())
$code =
$this->startClass($options['class'], $options['base_class'], $options['namespace']).
$this->addConstructor().
$this->addReset().
$this->addCompile().
$this->addIsCompiled().
$this->addServices().
Expand Down Expand Up @@ -831,6 +832,27 @@ public function __construct()
return $code;
}

/**
* Adds the reset method for a compiled container.
*
* @return string
*/
private function addReset()
{
return <<<EOF

/*{$this->docStar}
* {@inheritdoc}
*/
public function reset()
{
\$this->privates = array();
parent::reset();
}

EOF;
}

/**
* Adds the compile method for a compiled container.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public function __construct()
);
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public function __construct()
$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->privates = array();
parent::reset();
}

/**
* {@inheritdoc}
*/
Expand Down