-
-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheClearerPass.php
This file contains hidden or 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,50 @@ | ||
<?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; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Registers the cache clearers. | ||
* | ||
* @author Dustin Dobervich <ddobervich@gmail.com> | ||
*/ | ||
class AddCacheClearerPass implements CompilerPassInterface | ||
{ | ||
private $tag; | ||
private $serviceName; | ||
|
||
public function __construct($serviceName, $tag) | ||
{ | ||
$this->serviceName = $serviceName; | ||
$this->tag = $tag; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition($this->serviceName)) { | ||
return; | ||
} | ||
|
||
$clearers = array(); | ||
foreach ($container->findTaggedServiceIds($this->tag) as $id => $attributes) { | ||
$clearers[] = new Reference($id); | ||
} | ||
|
||
$container->getDefinition($this->serviceName)->replaceArgument(0, $clearers); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheWarmerPass.php
This file contains hidden or 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,53 @@ | ||
<?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; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
/** | ||
* Registers the cache warmers. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class AddCacheWarmerPass implements CompilerPassInterface | ||
{ | ||
use PriorityTaggedServiceTrait; | ||
|
||
private $tag; | ||
private $serviceName; | ||
|
||
public function __construct($serviceName, $tag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. See the discussion on #20250 (comment) |
||
{ | ||
$this->serviceName = $serviceName; | ||
$this->tag = $tag; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition($this->serviceName)) { | ||
return; | ||
} | ||
|
||
$warmers = $this->findAndSortTaggedServices($this->tag, $container); | ||
|
||
if (empty($warmers)) { | ||
return; | ||
} | ||
|
||
$container->getDefinition($this->serviceName)->replaceArgument(0, $warmers); | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.
@iltar
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 :)