-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEXT-28562 - Allow manipulating cache invalidation subscriber event l…
…isteners
- Loading branch information
1 parent
3c71319
commit 4ee545f
Showing
7 changed files
with
303 additions
and
183 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
changelog/_unreleased/2023-07-18-cache-invalidation-manipulation.md
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,10 @@ | ||
--- | ||
title: Cache invalidation manipulation | ||
issue: NEXT-28562 | ||
author: Oliver Skroblin | ||
author_email: [email protected] | ||
author_github: OliverSkroblin | ||
--- | ||
# Core | ||
* Changed `\Shopware\Core\Framework\Adapter\Cache\CacheInvalidationSubscriber` to allow manipulation of the cache invalidation event via compiler passes. The class isn't @internal anymore and can be manipulated via compiler pass by removing the event listener tags. | ||
* Added `\Shopware\Core\Framework\DependencyInjection\CompilerPass\RemoveEventListener` class, for easier removal of event listeners via compiler pass. |
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
38 changes: 38 additions & 0 deletions
38
src/Core/Framework/DependencyInjection/CompilerPass/RemoveEventListener.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,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DependencyInjection\CompilerPass; | ||
|
||
use Shopware\Core\Framework\Log\Package; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
#[Package('core')] | ||
abstract class RemoveEventListener | ||
{ | ||
/** | ||
* @param array<string[]> $remove | ||
*/ | ||
public static function remove(ContainerBuilder $builder, string $serviceId, array $remove): void | ||
{ | ||
if (!$builder->hasDefinition($serviceId)) { | ||
return; | ||
} | ||
|
||
$definition = $builder->getDefinition($serviceId); | ||
|
||
$listeners = $definition->getTag('kernel.event_listener'); | ||
|
||
$definition->clearTag('kernel.event_listener'); | ||
|
||
$map = \array_map(function (array $item) { | ||
return \implode('::', $item); | ||
}, $remove); | ||
|
||
foreach ($listeners as $listener) { | ||
$key = $listener['event'] . '::' . $listener['method']; | ||
|
||
if (!\in_array($key, $map, true)) { | ||
$definition->addTag('kernel.event_listener', $listener); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.