Skip to content

[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

Closed
wants to merge 3 commits into from

Conversation

Taluu
Copy link
Contributor

@Taluu Taluu commented Oct 19, 2016

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

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

@ro0NL
Copy link
Contributor

ro0NL commented Oct 19, 2016

@Taluu the passes depend on definitions, defined in the frameworkbundle, hence these are tight to the frameworkbundle as well.

https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml#L39

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.

@stof
Copy link
Member

stof commented Oct 19, 2016

@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;
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@ro0NL
Copy link
Contributor

ro0NL commented Oct 19, 2016

@stof dont get me wrong, 👍 for moving logic to components.. but not by just renaming :)

@Taluu Taluu force-pushed the move-cache-passes branch 2 times, most recently from 4c56ed0 to 38aa510 Compare October 19, 2016 18:33
private $tag;
private $definition;

public function __construct($definition = null, $tag = null)
Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

Base instead of Real?

Copy link
Contributor Author

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

Copy link
Contributor Author

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>
Copy link
Member

Choose a reason for hiding this comment

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

missing @deprecated ... annotation

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Member

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?

Copy link
Contributor Author

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) {
Copy link
Member

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

Copy link
Contributor Author

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';
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

serviceName instead of definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@Taluu Taluu force-pushed the move-cache-passes branch from 38aa510 to 1c4940e Compare October 19, 2016 19:02

public function __construct($serviceName = 'cache_clearer', $tag = 'kernel.cache_clearer')
{
if (null === $serviceName || null === $tag) {
Copy link
Member

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()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, fixed

@Taluu Taluu force-pushed the move-cache-passes branch from 1c4940e to edcd138 Compare October 19, 2016 19:04

public function __construct($serviceName = 'cache_warmer', $tag = 'kernel.cache_warmer')
{
if (2 > func_num_args()) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@ro0NL ro0NL Oct 19, 2016

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.

Copy link
Contributor Author

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. :}

Copy link
Contributor

@ro0NL ro0NL Oct 19, 2016

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.

Copy link
Member

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

Copy link
Contributor Author

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. :}

@Taluu Taluu force-pushed the move-cache-passes branch 3 times, most recently from 9efdbf6 to b5c3e39 Compare October 19, 2016 19:28
@ro0NL
Copy link
Contributor

ro0NL commented Oct 19, 2016

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
Copy link
Contributor

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);
}

Copy link
Contributor Author

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 ?)

Copy link
Contributor

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

Copy link
Contributor

@ro0NL ro0NL Oct 20, 2016

Choose a reason for hiding this comment

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

@iltar

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.

Copy link
Contributor

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)
Copy link
Member

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

Copy link
Contributor Author

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)

@xabbuh
Copy link
Member

xabbuh commented Oct 21, 2016

You now also need to update the minimum required version of the DependencyInjection component in the HttpKernel composer.json file.

@Taluu
Copy link
Contributor Author

Taluu commented Oct 24, 2016

@xabbuh Why ? I am not touching anything relating to DI in the Kernel. Unless you are talking about @iltar's suggestion ?

@xabbuh
Copy link
Member

xabbuh commented Oct 25, 2016

@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 deps=low build job).

@Taluu
Copy link
Contributor Author

Taluu commented Oct 26, 2016

Oh, indeed. I bumped it to 3.2 then, but I'm thinking of applying @iltar's sugggestion maybe (having a generic compiler pass, in DependencyInjection), which would make this bump not necessary,

Status: Needs Work

@fabpot
Copy link
Member

fabpot commented Mar 5, 2017

@Taluu Any news on this one?

@Taluu
Copy link
Contributor Author

Taluu commented Mar 5, 2017

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

@Taluu Taluu force-pushed the move-cache-passes branch from b29af77 to 7cdfcb4 Compare March 6, 2017 13:31
@Taluu Taluu force-pushed the move-cache-passes branch from 7cdfcb4 to 06aed12 Compare March 6, 2017 13:36
@Taluu
Copy link
Contributor Author

Taluu commented Mar 6, 2017

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"

@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

@Taluu Closing then, I prefer to merge one PR that solves the issue once and for all instead of having an intermediate solution. Thanks.

@fabpot fabpot closed this Mar 22, 2017
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@Taluu Taluu deleted the move-cache-passes branch August 8, 2019 09:05
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.

9 participants