Skip to content

[HttpKernel] Move services reset to Kernel::handle()+boot() #24709

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
Oct 30, 2017

Conversation

nicolas-grekas
Copy link
Member

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.

@@ -186,7 +187,15 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
$this->boot();
}

return $this->getHttpKernel()->handle($request, $type, $catch);
try {
if (0 === $this->requestStackSize++ && $this->container->has('services_resetter')) {
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be sufficient to check for a master request?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sufficient like calling reset() in kernel.terminate ? ;)
I'm sure there is code out there that would thank us being extra cautious here.

* @param string $tagName
*/
public function __construct($tagName = 'kernel.reset')
public function __construct($serviceName = 'services_resetter', $tagName = 'kernel.reset')
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any point about making the service name configurable, whereas it's hardcoded in the Kernel?

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 made other passes configurable, so is this one. Doesn't hurt...

Copy link
Contributor

@ro0NL ro0NL Oct 28, 2017

Choose a reason for hiding this comment

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

$serviceId, perhaps even $resetterServiceId. (ref)

@nicolas-grekas
Copy link
Member Author

comments addressed, and tests green

@nicolas-grekas nicolas-grekas changed the title [HttpKernel] Move services reset to Kernel::handle() [HttpKernel] Move services reset to Kernel::handle()+boot() Oct 30, 2017
$this->resetMethods = $resetMethods;
}

public function resetServices()
Copy link
Member

Choose a reason for hiding this comment

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

If the class is called ServicesResetter, shouldn't this method be called just reset() to follow official Symfony naming conventions?

Copy link
Member Author

Choose a reason for hiding this comment

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

why not, done :)

@nicolas-grekas
Copy link
Member Author

@derrabus @dmaicher ok for you here?

@javiereguiluz
Copy link
Member

javiereguiluz commented Oct 30, 2017

I have a very minor comment about the naming of services_resetter ID and ServicesResetter class name. It looks too specific to me. In the latest "A month of PHP-FIG" post @michaelcullum refers to this feature as "Interface for State Resettable classes". So, maybe StateResetter would be a more appropriate generic name? Maybe not. Just saying. Thanks!

@nicolas-grekas
Copy link
Member Author

@javiereguiluz I don't understand the consideration. Anyway, that's in the dI subnamespace, where we talk about "services", so I don't think we need to change the name.

@nicolas-grekas
Copy link
Member Author

Ok now I read the FIG's blog post :) Services is the term we use in Symfony, so the current naming is correct to me.

* @author Alexander M. Turek <me@derrabus.de>
* @author Nicolas Grekas <p@tchwork.com>
*/
class ServicesResetter
Copy link
Member

Choose a reason for hiding this comment

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

This class should probably be marked as @internal

Copy link
Member Author

Choose a reason for hiding this comment

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

internal it is now

@fabpot
Copy link
Member

fabpot commented Oct 30, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 4501a36 into symfony:3.4 Oct 30, 2017
fabpot added a commit that referenced this pull request Oct 30, 2017
…) (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
private $resettableServices;
private $resetMethods;

public function __construct(\Traversable $resettableServices, array $resetMethods)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about having only one argument with an iterator over an array of callables, so that instead of $service->{$this->resetMethods[$id]}(); you'll do $callable(), where $callable is [$service, $resetMethod]

Copy link
Member Author

Choose a reason for hiding this comment

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

the iterators build by the container using IteratorArgument are restricted to yielding services only, so that's not possible with the current primitives (and we don't really care, so all is fine :) )

@nicolas-grekas nicolas-grekas deleted the reset-kernel branch October 30, 2017 18:10
This was referenced Oct 30, 2017
if ($this->debug && !isset($_SERVER['SHELL_VERBOSITY'])) {
putenv('SHELL_VERBOSITY=3');
$_ENV['SHELL_VERBOSITY'] = 3;
$_SERVER['SHELL_VERBOSITY'] = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

May be put this login into DotEnv component?

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Aug 1, 2023
…lamirault)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[DependencyInjection] Update kernel.reset explanation

Try to fix #16806

Change was done in this PR symfony/symfony#24709

I'm open for better wording 😄

Commits
-------

a8803e2 [DependencyInjection] Update kernel.reset explanation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.