Skip to content
Permalink
Browse files

minor #28367 [DI] Forward Container::reset() to services implementing…

… ResetInterface (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[DI] Forward Container::reset() to services implementing ResetInterface

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | not really
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Should help the garbage collector during tests.

Commits
-------

5d26ba1 [DI] Forward Container::reset() to services implementing ResetInterface
  • Loading branch information...
fabpot committed Sep 5, 2018
2 parents 14fa58e + 5d26ba1 commit 0bd1f7538e1297ad2eb90c9fc0f98d66162ed43b
Showing with 24 additions and 387 deletions.
  1. +14 −1 src/Symfony/Component/DependencyInjection/Container.php
  2. +0 −11 src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
  3. +10 −1 src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
  4. +0 −11 ...t/DependencyInjection/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php
  5. +0 −11 ...dencyInjection/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php
  6. +0 −11 ...ndencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php
  7. +0 −11 ...y/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_without_constructor.php
  8. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php
  9. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php
  10. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php
  11. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php
  12. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php
  13. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php
  14. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php
  15. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php
  16. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php
  17. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php
  18. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt
  19. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php
  20. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_private.php
  21. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_public.php
  22. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php
  23. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_base64_env.php
  24. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_csv_env.php
  25. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dedup_lazy_proxy.php
  26. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php
  27. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php
  28. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php
  29. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_json_env.php
  30. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php
  31. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy.php
  32. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php
  33. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_in_expression.php
  34. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php
  35. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_service_locator_argument.php
  36. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php
  37. +0 −11 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_uninitialized_ref.php
@@ -20,6 +20,7 @@
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Contracts\Service\ResetInterface;
/**
* Container is a dependency injection container.
@@ -42,6 +43,7 @@ class Container implements ResettableContainerInterface
{
protected $parameterBag;
protected $services = array();
protected $privates = array();
protected $fileMap = array();
protected $methodMap = array();
protected $factories = array();
@@ -301,7 +303,18 @@ public function initialized($id)
*/
public function reset()
{
$this->services = $this->factories = array();
$services = $this->services + $this->privates;
$this->services = $this->factories = $this->privates = array();
foreach ($services as $service) {
try {
if ($service instanceof ResetInterface) {
$service->reset();
}
} catch (\Throwable $e) {
continue;
}
}
}
/**
@@ -960,11 +960,6 @@ class $class extends $baseClass
private \$parameters;
private \$targetDirs = array();
/*{$this->docStar}
* @internal but protected for BC on cache:clear
*/
protected \$privates = array();
public function __construct()
{
@@ -1011,12 +1006,6 @@ public function __construct()
$code .= <<<EOF
}
public function reset()
{
\$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Contracts\Service\ResetInterface;
class ContainerTest extends TestCase
{
@@ -317,11 +318,19 @@ public function testInitializedWithPrivateService()
public function testReset()
{
$c = new Container();
$c->set('bar', new \stdClass());
$c->set('bar', $bar = new class() implements ResetInterface {
public $resetCounter = 0;
public function reset()
{
++$this->resetCounter;
}
});
$c->reset();
$this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
$this->assertSame(1, $bar->resetCounter);
}
/**
@@ -21,11 +21,6 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
parent::__construct();
@@ -36,12 +31,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -21,24 +21,13 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = $this->privates = array();
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -21,11 +21,6 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
parent::__construct();
@@ -36,12 +31,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -21,24 +21,13 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = $this->privates = array();
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -21,24 +21,13 @@ class Container extends \Symfony\Component\DependencyInjection\Dump\AbstractCont
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = $this->privates = array();
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -19,24 +19,13 @@ class ProjectServiceContainer extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = $this->privates = array();
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -19,11 +19,6 @@ class ProjectServiceContainer extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->parameters = $this->getDefaultParameters();
@@ -36,12 +31,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -19,11 +19,6 @@ class ProjectServiceContainer extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$dir = __DIR__;
@@ -40,12 +35,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -19,11 +19,6 @@ class ProjectServiceContainer extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = $this->privates = array();
@@ -34,12 +29,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -19,11 +19,6 @@ class ProjectServiceContainer extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = $this->privates = array();
@@ -35,12 +30,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -19,11 +19,6 @@ class ProjectServiceContainer extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$this->services = $this->privates = array();
@@ -34,12 +29,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
@@ -19,11 +19,6 @@ class Symfony_DI_PhpDumper_Test_EnvParameters extends Container
private $parameters;
private $targetDirs = array();
/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
public function __construct()
{
$dir = __DIR__;
@@ -41,12 +36,6 @@ public function __construct()
$this->aliases = array();
}
public function reset()
{
$this->privates = array();
parent::reset();
}
public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
Oops, something went wrong.

0 comments on commit 0bd1f75

Please sign in to comment.
You can’t perform that action at this time.