You've already forked php-flasher
mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-04-05 12:32:55 +01:00
77 lines
1.5 KiB
PHP
77 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Flasher\Prime\Storage;
|
|
|
|
use Flasher\Prime\Envelope;
|
|
use Flasher\Prime\Stamp\HopsStamp;
|
|
|
|
final class StorageManager implements StorageManagerInterface
|
|
{
|
|
/**
|
|
* @var StorageInterface
|
|
*/
|
|
private $storage;
|
|
|
|
/**
|
|
* @param StorageInterface $storage
|
|
*/
|
|
public function __construct(StorageInterface $storage)
|
|
{
|
|
$this->storage = $storage;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function flush($envelopes)
|
|
{
|
|
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
|
|
|
|
$this->storage->remove($envelopes);
|
|
|
|
foreach ($envelopes as $envelope) {
|
|
$replayStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
|
|
$replayCount = null === $replayStamp ? 0 : $replayStamp->getCount() - 1;
|
|
|
|
if (1 > $replayCount) {
|
|
continue;
|
|
}
|
|
|
|
$envelope->with(new HopsStamp($replayCount));
|
|
$this->storage->add($envelope);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function all()
|
|
{
|
|
return $this->storage->all();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function add(Envelope $envelope)
|
|
{
|
|
$this->storage->add($envelope);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function remove($envelopes)
|
|
{
|
|
$this->storage->remove($envelopes);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function clear()
|
|
{
|
|
$this->storage->clear();
|
|
}
|
|
}
|