Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #24709 [HttpKernel] Move services reset to Kernel::handle()+boot(…
…) (nicolas-grekas) This PR was merged into the 3.4 branch. Discussion ---------- [HttpKernel] Move services reset to Kernel::handle()+boot() | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24552 | License | MIT | Doc PR | - This is an alternative to #24697 (which uses middlewares). This PR adds a new `services_resetter` service that the Kernel calls on 2nd root requests to reset services. Instead of #24697 which plans for optional enabling of the services reset, this approach moves the responsibility of calling the services resetter to the core Kernel class, so that no configuration/middleware/etc. is required at all, and no overhead exists at all for regular requests. Commits ------- 4501a36 [HttpKernel] Move services reset to Kernel
- Loading branch information
Showing
9 changed files
with
164 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Symfony/Component/HttpKernel/DependencyInjection/ServicesResetter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\DependencyInjection; | ||
|
||
/** | ||
* Resets provided services. | ||
* | ||
* @author Alexander M. Turek <me@derrabus.de> | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
* | ||
* @internal | ||
*/ | ||
class ServicesResetter | ||
{ | ||
private $resettableServices; | ||
private $resetMethods; | ||
|
||
public function __construct(\Traversable $resettableServices, array $resetMethods) | ||
{ | ||
$this->resettableServices = $resettableServices; | ||
$this->resetMethods = $resetMethods; | ||
} | ||
|
||
public function reset() | ||
{ | ||
foreach ($this->resettableServices as $id => $service) { | ||
$service->{$this->resetMethods[$id]}(); | ||
} | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
src/Symfony/Component/HttpKernel/EventListener/ServiceResetListener.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ServicesResetterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; | ||
use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService; | ||
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService; | ||
|
||
class ServicesResetterTest extends TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
ResettableService::$counter = 0; | ||
ClearableService::$counter = 0; | ||
} | ||
|
||
public function testResetServices() | ||
{ | ||
$resetter = new ServicesResetter(new \ArrayIterator(array( | ||
'id1' => new ResettableService(), | ||
'id2' => new ClearableService(), | ||
)), array( | ||
'id1' => 'reset', | ||
'id2' => 'clear', | ||
)); | ||
|
||
$resetter->reset(); | ||
|
||
$this->assertEquals(1, ResettableService::$counter); | ||
$this->assertEquals(1, ClearableService::$counter); | ||
} | ||
} |
Oops, something went wrong.