mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Flasher\Prime\EventDispatcher\EventSubscriber;
|
|
|
|
use Flasher\Prime\EventDispatcher\Event\PostFlushEvent;
|
|
use Flasher\Prime\Stamp\HopsStamp;
|
|
use Flasher\Prime\Storage\StorageInterface;
|
|
|
|
class RemoveRenderedEnvelopesSubscriber implements EventSubscriberInterface
|
|
{
|
|
/**
|
|
* @var StorageInterface
|
|
*/
|
|
private $storage;
|
|
|
|
/**
|
|
* @param StorageInterface $storage
|
|
*/
|
|
public function __construct(StorageInterface $storage)
|
|
{
|
|
$this->storage = $storage;
|
|
}
|
|
|
|
/**
|
|
* @param PostFlushEvent $event
|
|
*/
|
|
public function __invoke(PostFlushEvent $event)
|
|
{
|
|
foreach ($event->getEnvelopes() as $envelope) {
|
|
$replayStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
|
$replayCount = null === $replayStamp ? 0 : $replayStamp->getAmount() - 1;
|
|
|
|
if (1 > $replayCount) {
|
|
continue;
|
|
}
|
|
|
|
$envelope->with(new HopsStamp($replayCount));
|
|
$this->storage->add($envelope);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public static function getSubscribedEvents()
|
|
{
|
|
return 'Flasher\Prime\EventDispatcher\Event\PostFlushEvent';
|
|
}
|
|
}
|