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
81 lines
1.7 KiB
PHP
81 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Flasher\Prime\Storage;
|
|
|
|
use Flasher\Prime\Envelope;
|
|
use Flasher\Prime\EventDispatcher\Event\PostFlushEvent;
|
|
use Flasher\Prime\EventDispatcher\Event\PreFlushEvent;
|
|
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
|
|
use Flasher\Prime\Stamp\HopsStamp;
|
|
|
|
final class StorageManager implements StorageManagerInterface
|
|
{
|
|
/**
|
|
* @var StorageInterface
|
|
*/
|
|
private $storage;
|
|
|
|
/**
|
|
* @var EventDispatcherInterface
|
|
*/
|
|
private $eventDispatcher;
|
|
|
|
/**
|
|
* @param StorageInterface $storage
|
|
* @param EventDispatcherInterface $eventDispatcher
|
|
*/
|
|
public function __construct(StorageInterface $storage, EventDispatcherInterface $eventDispatcher)
|
|
{
|
|
$this->storage = $storage;
|
|
$this->eventDispatcher = $eventDispatcher;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function flush($envelopes)
|
|
{
|
|
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
|
|
|
|
$event = new PreFlushEvent($envelopes);
|
|
$this->eventDispatcher->dispatch($event);
|
|
|
|
$this->storage->remove($event->getEnvelopes());
|
|
|
|
$event = new PostFlushEvent($envelopes);
|
|
$this->eventDispatcher->dispatch($event);
|
|
}
|
|
|
|
/**
|
|
* @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();
|
|
}
|
|
}
|