-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Kernel] Move the cache compiler passes into the Kernel component #20250
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
Conversation
@Taluu the passes depend on definitions, defined in the frameworkbundle, hence these are tight to the frameworkbundle as well. ie. the passes are still unuseable (as is) with just the HttpKernel+DI component. edit: point is; imo. these passes are designed in scope of the frameworkbundle. Although they could be used standalone (and i understand in that case you dont want to depend on the frameworkbundle, but rather the httpkernel component) they are not designed from a component point of view (eg. the tag name, definitions id's are hardcoded). Ie. imo the added value is minimal then to put it in a component. |
@ro0NL any time we moved passes to the components, we made the id and tag names configurable in the constructor (defaulting to the names used in the fullstack). |
@@ -9,7 +9,7 @@ | |||
* file that was distributed with this source code. | |||
*/ | |||
|
|||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; | |||
namespace Symfony\Component\HttpKernel\DependencyInjection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yo cannot just move a class. It is a BC break (as it deletes the old class). You need to keep the class in FrameworkBundle (making it extend the new one to avoid duplication) but deprecating it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I actually wasn't sure if this was really needed, but I'll do that then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@stof dont get me wrong, 👍 for moving logic to components.. but not by just renaming :) |
4c56ed0
to
38aa510
Compare
private $tag; | ||
private $definition; | ||
|
||
public function __construct($definition = null, $tag = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just __construct($definition = 'cache_warmer', $tag = 'kernel.cache_warmer')
, that would be fine for 3.2 as well right.. (ref)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I wanted to add a deprecation on the fact that one should add arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(So that on 4.0 we have required args)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about making them required now, and call parent::__construct
from the legacy class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, see @nicolas-grekas' comments. :}
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass as RealAddCacheClearerPass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base instead of Real?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hesitated, but both are fine, so I'll change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass as RealAddCacheClearerPass; | ||
|
||
@trigger_error('The '.AddCacheClearerPass::class.' class is deprecated since version 3.2 and will be removed in 4.0. Use the '.RealAddCacheClearerPass::class.' class instead.', E_USER_DEPRECATED); | ||
|
||
/** | ||
* Registers the cache clearers. | ||
* | ||
* @author Dustin Dobervich <ddobervich@gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing @deprecated ...
annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
{ | ||
/** | ||
* @group legacy | ||
* @dataProvider nullProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the provider, a single and simple use is enough
the @legacy
annotation should be moved to the class level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OH, in fact, is this class required at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, thought it would be a way to introduce some tests on that class, but I can remove it
|
||
public function __construct($definition = null, $tag = null) | ||
{ | ||
if (null === $definition || null === $tag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use func_num_args instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if (null === $definition || null === $tag) { | ||
@trigger_error('The '.static::class.' class\' constructor needs two parameters since version 3.2, and will become required in 4.0.', E_USER_DEPRECATED); | ||
|
||
$definition = 'cache_clearer'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be the default values in the method signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as I just learned that indeed func_num_args
returns the number of args given to a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
class AddCacheClearerPass implements CompilerPassInterface | ||
{ | ||
private $tag; | ||
private $definition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serviceName instead of definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
38aa510
to
1c4940e
Compare
|
||
public function __construct($serviceName = 'cache_clearer', $tag = 'kernel.cache_clearer') | ||
{ | ||
if (null === $serviceName || null === $tag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (2 > func_num_args()) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, fixed
1c4940e
to
edcd138
Compare
|
||
public function __construct($serviceName = 'cache_warmer', $tag = 'kernel.cache_warmer') | ||
{ | ||
if (2 > func_num_args()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Taluu AFAIK the BC promise allows you to add a constructor without mandatory arguments.., ie you may add to the legacy class and call parent::__construct('cache_warmer', 'kernel.cache_warmer')
. That would give us required args for the new class already in 3.2... right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does work to call new ...
without arguments, You'll just have a deprecated error, which is shown in dev env and in the logs AFAIK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With new class i meant Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass
(a new class definition). It can have required args, that can be provided by the legacy class (the old class) by adding a constructor...
// Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass
public function __construct() {
parent::__construct('cache_warmer', 'kernel.cache_warmer');
}
ie. why make them required as of 4.0 instead of 3.2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see where you are getting at (it was even one of my first ideas actually), but I don't think it is really useful, and just let the deprecated error be triggered. Especially as it is silenced (with the @
in front of the trigger_error
), it will only be logged and that's pretty much it. So you can still continue to use with new ...
and without args, you'll just have a little line on your logs. :}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I don't think it is really useful,
This is part of a component now.. imo. it shoud make no assumptions on naming, hence required args 👍
So you can still continue to use with new ... and without args
Only until 4.0, as we already decided that. Im not sure why we want to bridge that with optional args now (again; for a new class (definition)). It doesnt make sense to me nor does it solve a DX issue, as the old class still works without args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ro0NL is right! We don't need this deprecation on the constructor: let's make the new construcor require 2 args, and the constructor of the legacy class set them as required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, i'll revert back to the previous idea i had and you gave. :}
9efdbf6
to
b5c3e39
Compare
Technically you still need to document the added constructor in the UPGADE file :) But im not sure it really counts for a deprecated class anyway. @nicolas-grekas ? |
* | ||
* @author Dustin Dobervich <ddobervich@gmail.com> | ||
*/ | ||
class AddCacheClearerPass implements CompilerPassInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides of the sort, this pass and the AddCacheWarmerPass
are rather identical now (and there's probably more).
A lot of times, a compiler pass for tags is used to collect a bunch of references and that's it. What about a more generic class?
Just a brain fart:
class CollectAndInjectTaggedServicePass implements CompilerPassInterface
{
const NO_FLAGS = 0;
const SORT_BY_PRIORITY = 1;
public function __construct($targetService, $serviceArgumentIndex, $tag, $flags = self::NO_FLAGS);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, then this would need to be in the DependencyInjection
component, but I am not sure this should be the goal of this PR (but a later one probably ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR would introduce 2 new classes in the component while it might be solved with a (re-usable) generic solution, which means those 2 new classes would not be added unless you use them for inheritance templating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of times, a compiler pass for tags is used to collect a bunch of references and that's it.
Dont forget the handling of collected references, this is probably the true problem. Currently the passes still make assumptions about what to do with it (pass it as constructor arguments, whereas others add a method call (addSomething(new Ref())
), ie. we assume argument index 0 is available on the implementation side, that's why i still think this belongs to the application/framework. Although i can live with it like this in the component as well.
Nevertheless, a generic approach should solve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yeah, i thought about a TagCollectingPass
many, many times :)
private $tag; | ||
private $serviceName; | ||
|
||
public function __construct($serviceName, $tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our other compiler passes in the component don't make these argument required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the discussion on #20250 (comment)
You now also need to update the minimum required version of the DependencyInjection component in the HttpKernel |
@Taluu You are moving compiler passes to the HttpKernel component which make use of a trait that is not available in all versions of the DependencyInjection component (see the failing |
Oh, indeed. I bumped it to Status: Needs Work |
@Taluu Any news on this one? |
I don't know if it was decided or not to have a generic tag compiler pass (if it is the case, then I guess this PR can closed). If not, I just need to rebase I guess, as 3.2 was released some months ago |
PR Rebased. I'm going to do the changes suggested by @iltar on another PR, feel free to merge or close it if you don't think it is worth it to have an "inbetween" |
@Taluu Closing then, I prefer to merge one PR that solves the issue once and for all instead of having an intermediate solution. Thanks. |
Looking at the passes, for one who doesn't want to use the Framework Bundle (like me, in a minimal app) but has still need some accesses to part of it (such as cache clearers / cache warmers), and as these two passes are not tied to the framwork bundle (but are to the kernel component), I thought it would be better to move these two passes in the Kernel.
Not sure what branch I should target, so I targetted master... And I am not sure if this is a bc break, as these two classes are not final but not tagged
@api