remove middelawares and delete renderer and rename presenter to renderer

This commit is contained in:
Khoubza Younes
2020-12-08 22:33:56 +01:00
parent 2e33aa44be
commit fa21d27ccd
69 changed files with 327 additions and 544 deletions
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
+1 -1
View File
@@ -4,7 +4,7 @@ namespace Flasher\Laravel\Middleware;
use Flasher\Prime\Config\ConfigInterface;
use Flasher\Prime\FlasherInterface;
use Flasher\Prime\Presenter\Adapter\HtmlPresenter;
use Flasher\Prime\Renderer\Adapter\HtmlPresenter;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -6,11 +6,11 @@ use Flasher\Laravel\Config\Config;
use Flasher\Laravel\FlasherServiceProvider;
use Flasher\Laravel\Storage\Storage;
use Flasher\Prime\EventDispatcher\EventDispatcher;
use Flasher\Prime\EventDispatcher\EventListener\PrePersistListener;
use Flasher\Prime\EventDispatcher\EventListener\PostFilterListener;
use Flasher\Prime\EventDispatcher\EventListener\StampsListener;
use Flasher\Prime\EventDispatcher\EventListener\FilterListener;
use Flasher\Prime\EventDispatcher\EventListener\PostFlushListener;
use Flasher\Prime\EventDispatcher\EventListener\PostBuildListener;
use Flasher\Prime\Filter\DefaultFilter;
use Flasher\Prime\Filter\Filter;
use Flasher\Prime\Filter\FilterBuilder;
use Flasher\Prime\Filter\FilterManager;
use Flasher\Prime\Flasher;
@@ -19,9 +19,9 @@ use Flasher\Prime\Middleware\AddDelayStampMiddleware;
use Flasher\Prime\Middleware\AddHopsStampMiddleware;
use Flasher\Prime\Middleware\AddPriorityStampMiddleware;
use Flasher\Prime\Middleware\FlasherBus;
use Flasher\Prime\Presenter\Adapter\HtmlPresenter;
use Flasher\Prime\Presenter\Adapter\Presenter;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\Adapter\HtmlPresenter;
use Flasher\Prime\Renderer\Adapter\Presenter;
use Flasher\Prime\Renderer\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
use Flasher\Prime\Storage\StorageManager;
use Illuminate\Container\Container;
@@ -101,9 +101,9 @@ class Laravel implements ServiceProviderInterface
$this->app->singleton('flasher.event_dispatcher', function (Application $app) {
$eventDispatcher = new EventDispatcher();
$eventDispatcher->addSubscriber(new PostFilterListener($app['flasher.storage']));
$eventDispatcher->addSubscriber(new FilterListener($app['flasher.storage']));
$eventDispatcher->addSubscriber(new PostFlushListener($app['flasher.storage']));
$eventDispatcher->addSubscriber(new PrePersistListener($app['flasher.flasher_bus']));
$eventDispatcher->addSubscriber(new StampsListener($app['flasher.flasher_bus']));
$eventDispatcher->addSubscriber(new PostBuildListener($app['flasher.storage']));
return $eventDispatcher;
@@ -111,7 +111,7 @@ class Laravel implements ServiceProviderInterface
$this->app->singleton('flasher.filter_manager', function (Application $app) {
$filterManager = new FilterManager($app['flasher.config']);
$filterManager->addDriver(new DefaultFilter($app['flasher.filter_builder']));
$filterManager->addDriver(new Filter($app['flasher.filter_builder']));
return $filterManager;
});
@@ -146,7 +146,7 @@ class Laravel implements ServiceProviderInterface
$this->app->alias('flasher.storage_manager', 'Flasher\Laravel\Storage\StorageManager');
$this->app->alias('flasher.filter_manager', 'Flasher\Prime\Filter\FilterManager');
$this->app->alias('flasher.filter_builder', 'Flasher\Prime\Filter\FilterBuilder');
$this->app->alias('flasher.filter.default', 'Flasher\Prime\Filter\DefaultFilter');
$this->app->alias('flasher.filter.default', 'Flasher\Prime\Filter\Filter');
$this->app->alias('flasher.presenter.html', 'Flasher\Prime\Presenter\Adapter\HtmlPresenter');
$this->app->alias('flasher.presenter.json', 'Flasher\Prime\Presenter\Adapter\Presenter');
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
@@ -47,7 +47,7 @@ class Laravel implements ServiceProviderInterface
$this->app->alias('flasher.renderer.noty', 'Flasher\Noty\Prime\NotyRenderer');
$this->app->extend('flasher', function (Flasher $flasher, Container $app) {
$flasher->addDriver($app['flasher.factory.noty']);
$flasher->addFactory($app['flasher.factory.noty']);
return $flasher;
});
@@ -21,7 +21,7 @@ class FlasherNotyServiceProviderTest extends TestCase
$extensions = $property->getValue($flasher);
$this->assertCount(1, $extensions);
$this->assertInstanceOf('Flasher\Prime\Factory\FlasherFactoryInterface', $extensions[0]);
$this->assertInstanceOf('Flasher\Prime\Factory\FactoryInterface', $extensions[0]);
}
public function testConfigNotyInjectedInGlobalNotifyConfig()
+1 -1
View File
@@ -38,7 +38,7 @@ final class NotyFactory extends AbstractFactory
*/
public function createNotificationBuilder()
{
return new NotyBuilder($this->getEventDispatcher(), $this->createNotification(), 'noty');
return new NotyBuilder($this->getStorageManager(), $this->createNotification(), 'noty');
}
/**
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
@@ -47,7 +47,7 @@ class Laravel implements ServiceProviderInterface
$this->app->alias('flasher.renderer.notyf', 'Flasher\Notyf\Prime\NotyfRenderer');
$this->app->extend('flasher', function (Flasher $manager, Container $app) {
$manager->addDriver($app['flasher.factory.notyf']);
$manager->addFactory($app['flasher.factory.notyf']);
return $manager;
});
@@ -21,7 +21,7 @@ final class FlasherNotyfServiceProviderTest extends TestCase
$extensions = $property->getValue($flasher);
$this->assertCount(1, $extensions);
$this->assertInstanceOf('Flasher\Prime\Factory\FlasherFactoryInterface', $extensions[0]);
$this->assertInstanceOf('Flasher\Prime\Factory\FactoryInterface', $extensions[0]);
}
public function testConfigNotyfInjectedInGlobalNotifyConfig()
+1 -1
View File
@@ -19,7 +19,7 @@ final class NotyfFactory extends AbstractFactory
*/
public function createNotificationBuilder()
{
return new PnotifyBuilder($this->getEventDispatcher(), $this->createNotification(), 'notyf');
return new PnotifyBuilder($this->getStorageManager(), $this->createNotification(), 'notyf');
}
/**
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
@@ -47,7 +47,7 @@ class Laravel implements ServiceProviderInterface
$this->app->alias('flasher.renderer.pnotify', 'Flasher\Pnotify\Prime\PnotifyRenderer');
$this->app->extend('flasher', function (Flasher $manager, Container $app) {
$manager->addDriver($app['flasher.factory.pnotify']);
$manager->addFactory($app['flasher.factory.pnotify']);
return $manager;
});
@@ -21,7 +21,7 @@ class FlasherPnotifyServiceProviderTest extends TestCase
$extensions = $property->getValue($flasher);
$this->assertCount(1, $extensions);
$this->assertInstanceOf('Flasher\Prime\Factory\FlasherFactoryInterface', $extensions[0]);
$this->assertInstanceOf('Flasher\Prime\Factory\FactoryInterface', $extensions[0]);
}
public function testConfigPnotifyInjectedInGlobalNotifyConfig()
+1 -1
View File
@@ -19,7 +19,7 @@ final class PnotifyFactory extends AbstractFactory
*/
public function createNotificationBuilder()
{
return new PnotifyBuilder($this->getEventDispatcher(), $this->createNotification(), 'pnotify');
return new PnotifyBuilder($this->getStorageManager(), $this->createNotification(), 'pnotify');
}
/**
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
+7 -11
View File
@@ -2,19 +2,15 @@
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Notification\NotificationBuilderInterface;
use Flasher\Prime\Notification\NotificationInterface;
override(Envelope::get(), type(0));
override(ManagerInterface::make(0), map(['' => '@']));
registerArgumentsSet('notificationTypes', NotificationInterface::TYPE_SUCCESS, NotificationInterface::TYPE_ERROR, NotificationInterface::TYPE_WARNING, NotificationInterface::TYPE_INFO);
registerArgumentsSet('notificationTypes',
NotificationInterface::TYPE_SUCCESS,
NotificationInterface::TYPE_ERROR,
NotificationInterface::TYPE_INFO,
NotificationInterface::TYPE_INFO,
);
override(Envelope::get(0), type(0));
expectedArguments(NotificationBuilderInterface::type(), 1, argumentsSet('notificationTypes'));
expectedArguments(NotificationBuilderInterface::addFlash(), 1, argumentsSet('notificationTypes'));
expectedArguments(NotificationInterface::setType(), 1, argumentsSet('notificationTypes'));
expectedArguments(NotificationBuilder::type(), 1, argumentsSet('notificationTypes'));
expectedReturnValues(NotificationInterface::setType(), 1, argumentsSet('notificationTypes'));
expectedReturnValues(NotificationInterface::getType(), argumentsSet('notificationTypes'));
+8 -8
View File
@@ -18,10 +18,10 @@ final class Envelope implements NotificationInterface
private $stamps = array();
/**
* @param Envelope|NotificationInterface $notification
* @param StampInterface[] $stamps
* @param NotificationInterface $notification
* @param StampInterface[] $stamps
*/
public function __construct($notification, $stamps = array())
public function __construct(NotificationInterface $notification, $stamps = array())
{
$this->notification = $notification;
$this->with(is_array($stamps) ? $stamps : array_slice(func_get_args(), 1));
@@ -30,16 +30,16 @@ final class Envelope implements NotificationInterface
/**
* Makes sure the notification is in an Envelope and adds the given stamps.
*
* @param NotificationInterface|Envelope $notification
* @param StampInterface[] $stamps
* @param NotificationInterface $notification
* @param StampInterface[] $stamps
*
* @return Envelope
*/
public static function wrap($notification, array $stamps = array())
public static function wrap(NotificationInterface $notification, $stamps = array())
{
$envelope = $notification instanceof self ? $notification : new self($notification);
return $envelope->with($stamps);
return $envelope->with(is_array($stamps) ? $stamps : array_slice(func_get_args(), 1));
}
/**
@@ -47,7 +47,7 @@ final class Envelope implements NotificationInterface
*
* @return Envelope a new Envelope instance with additional stamp
*/
public function with($stamps = array())
public function with($stamps)
{
$stamps = is_array($stamps) ? $stamps : func_get_args();
@@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event;
use Flasher\Prime\Envelope;
final class PostBuildEvent
final class BuildEvent
{
/**
* @var Envelope
@@ -12,15 +12,15 @@ final class FilterEvent
private $envelopes;
/**
* @var array|string
* @var string
*/
private $criteria;
/**
* @param Envelope[] $envelopes
* @param string|array $criteria
* @param array $criteria
*/
public function __construct(array $envelopes, $criteria = array())
public function __construct(array $envelopes, array $criteria)
{
$this->envelopes = $envelopes;
$this->criteria = $criteria;
@@ -43,7 +43,7 @@ final class FilterEvent
}
/**
* @return array|string
* @return array
*/
public function getCriteria()
{
@@ -51,9 +51,9 @@ final class FilterEvent
}
/**
* @param array|string $criteria
* @param array $criteria
*/
public function setCriteria($criteria)
public function setCriteria(array $criteria)
{
$this->criteria = $criteria;
}
@@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event;
use Flasher\Prime\Envelope;
final class PreRemoveEvent
final class PersistEvent
{
/**
* @var Envelope[]
@@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event;
use Flasher\Prime\Envelope;
final class PreUpdateEvent
final class RemoveEvent
{
/**
* @var Envelope[]
@@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event;
use Flasher\Prime\Envelope;
final class PrePersistEvent
final class UpdateEvent
{
/**
* @var Envelope[]
@@ -60,7 +60,7 @@ final class EventDispatcher implements EventDispatcherInterface
* @param callable[] $listeners
* @param object $event
*/
protected function callListeners(array $listeners, $event)
private function callListeners(array $listeners, $event)
{
foreach ($listeners as $listener) {
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
@@ -0,0 +1,47 @@
<?php
namespace Flasher\Prime\EventDispatcher\EventListener;
use Flasher\Prime\EventDispatcher\Event\FilterEvent;
use Flasher\Prime\Envelope;
use Flasher\Prime\Filter\FilterInterface;
final class FilterListener implements EventSubscriberInterface
{
/**
* @var FilterInterface
*/
private $filter;
/**
* @param FilterInterface $filter
*/
public function __construct(FilterInterface $filter)
{
$this->filter = $filter;
}
/**
* @param FilterEvent $event
*
* @return Envelope[]
*/
public function __invoke(FilterEvent $event)
{
$criteria = $event->getCriteria();
$criteria['delay'] = 0;
$criteria['hops']['min'] = 1;
$envelopes = $this->filter->filter($event->getEnvelopes(), $criteria);
$event->setEnvelopes($envelopes);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return 'Flasher\Prime\EventDispatcher\Event\FilterEvent';
}
}
@@ -2,7 +2,7 @@
namespace Flasher\Prime\EventDispatcher\EventListener;
use Flasher\Prime\EventDispatcher\Event\PostBuildEvent;
use Flasher\Prime\EventDispatcher\Event\BuildEvent;
use Flasher\Prime\Storage\StorageManagerInterface;
final class PostBuildListener implements EventSubscriberInterface
@@ -21,9 +21,9 @@ final class PostBuildListener implements EventSubscriberInterface
}
/**
* @param PostBuildEvent $event
* @param BuildEvent $event
*/
public function __invoke(PostBuildEvent $event)
public function __invoke(BuildEvent $event)
{
$this->storageManager->add($event->getEnvelope());
}
@@ -33,6 +33,6 @@ final class PostBuildListener implements EventSubscriberInterface
*/
public static function getSubscribedEvents()
{
return 'Flasher\Prime\EventDispatcher\Event\PostBuildEvent';
return 'Flasher\Prime\EventDispatcher\Event\BuildEvent';
}
}
@@ -1,59 +0,0 @@
<?php
namespace Flasher\Prime\EventDispatcher\EventListener;
use Flasher\Prime\EventDispatcher\Event\FilterEvent;
use Flasher\Prime\Envelope;
use Flasher\Prime\Stamp\DelayStamp;
use Flasher\Prime\Storage\StorageManagerInterface;
final class PostFilterListener implements EventSubscriberInterface
{
/**
* @var StorageManagerInterface
*/
private $storageManager;
/**
* @param StorageManagerInterface $storageManager
*/
public function __construct(StorageManagerInterface $storageManager)
{
$this->storageManager = $storageManager;
}
/**
* @param FilterEvent $event
*
* @return Envelope[]
*/
public function __invoke(FilterEvent $event)
{
$envelopes = $event->getEnvelopes();
$filtered = array();
foreach ($envelopes as $envelope) {
$hopsStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp');
$delayStamp = $envelope->get('Flasher\Prime\Stamp\DelayStamp');
if (0 < $hopsStamp->getAmount() && 0 === $delayStamp->getDelay()) {
$filtered[] = $envelope;
continue;
}
$envelope->withStamp(new DelayStamp($delayStamp->getDelay() - 1));
$this->storageManager->update($envelope);
}
$event->setEnvelopes($filtered);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return 'Flasher\Prime\EventDispatcher\Event\FilterEvent';
}
}
@@ -3,19 +3,20 @@
namespace Flasher\Prime\EventDispatcher\EventListener;
use Flasher\Prime\Envelope;
use Flasher\Prime\EventDispatcher\Event\PrePersistEvent;
use Flasher\Prime\EventDispatcher\Event\PersistEvent;
use Flasher\Prime\EventDispatcher\Event\UpdateEvent;
use Flasher\Prime\Stamp\CreatedAtStamp;
use Flasher\Prime\Stamp\DelayStamp;
use Flasher\Prime\Stamp\HopsStamp;
use Flasher\Prime\Stamp\PriorityStamp;
use Flasher\Prime\Stamp\UuidStamp;
final class PrePersistListener implements EventSubscriberInterface
final class StampsListener implements EventSubscriberInterface
{
/**
* @param PrePersistEvent $event
* @param PersistEvent|UpdateEvent $event
*/
public function __invoke(PrePersistEvent $event)
public function __invoke($event)
{
foreach ($event->getEnvelopes() as $envelope) {
$this->attachStamps($envelope);
@@ -53,6 +54,9 @@ final class PrePersistListener implements EventSubscriberInterface
*/
public static function getSubscribedEvents()
{
return 'Flasher\Prime\EventDispatcher\Event\PrePersistEvent';
return array(
'Flasher\Prime\EventDispatcher\Event\PersistEvent',
'Flasher\Prime\EventDispatcher\Event\UpdateEvent',
);
}
}
+11 -15
View File
@@ -2,27 +2,23 @@
namespace Flasher\Prime\Factory;
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
use Flasher\Prime\Notification\Notification;
use Flasher\Prime\Notification\NotificationBuilder;
use Flasher\Prime\Notification\NotificationBuilderInterface;
use Flasher\Prime\Storage\StorageManagerInterface;
/**
* @mixin NotificationBuilderInterface
*/
abstract class AbstractFactory implements FlasherFactoryInterface
abstract class AbstractFactory implements FactoryInterface
{
/**
* @var EventDispatcherInterface
* @var StorageManagerInterface
*/
protected $eventDispatcher;
protected $storageManager;
/**
* @param EventDispatcherInterface $eventDispatcher
* @param StorageManagerInterface $eventDispatcher
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
public function __construct(StorageManagerInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
$this->storageManager = $eventDispatcher;
}
/**
@@ -30,7 +26,7 @@ abstract class AbstractFactory implements FlasherFactoryInterface
*/
public function createNotificationBuilder()
{
return new NotificationBuilder($this->getEventDispatcher(), new Notification(), 'default');
return new NotificationBuilder($this->getStorageManager(), new Notification(), 'default');
}
/**
@@ -47,10 +43,10 @@ abstract class AbstractFactory implements FlasherFactoryInterface
}
/**
* @return EventDispatcherInterface
* @return StorageManagerInterface
*/
public function getEventDispatcher()
public function getStorageManager()
{
return $this->eventDispatcher;
return $this->storageManager;
}
}
@@ -7,7 +7,7 @@ use Flasher\Prime\Notification\NotificationBuilderInterface;
/**
* @mixin NotificationBuilderInterface
*/
interface FlasherFactoryInterface
interface FactoryInterface
{
/**
* @return NotificationBuilderInterface
+5 -1
View File
@@ -17,7 +17,11 @@ final class CriteriaBuilder
*/
private $criteria;
public function __construct(FilterBuilder $filterBuilder, $criteria = array())
/**
* @param FilterBuilder $filterBuilder
* @param array $criteria
*/
public function __construct(FilterBuilder $filterBuilder, array $criteria)
{
$this->filterBuilder = $filterBuilder;
$this->criteria = $criteria;
-32
View File
@@ -1,32 +0,0 @@
<?php
namespace Flasher\Prime\Filter;
use Flasher\Prime\Envelope;
final class DefaultFilter implements FilterInterface
{
/**
* @var FilterBuilder
*/
private $filterBuilder;
/**
* @param FilterBuilder $filterBuilder
*/
public function __construct(FilterBuilder $filterBuilder)
{
$this->filterBuilder = $filterBuilder;
}
/**
* @param Envelope[] $envelopes
* @param array $criteria
*
* @return array
*/
public function filter($envelopes, $criteria = array())
{
return $this->filterBuilder->withCriteria($criteria)->filter($envelopes);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Flasher\Prime\Filter;
final class Filter implements FilterInterface
{
/**
* @var FilterBuilder
*/
private $filterBuilder;
/**
* @param FilterBuilder $filterBuilder
*/
public function __construct(FilterBuilder $filterBuilder = null)
{
$this->filterBuilder = $filterBuilder ?: new FilterBuilder();
}
/**
* @inheritDoc
*/
public function filter(array $envelopes, array $criteria)
{
return $this->filterBuilder->withCriteria($criteria)->filter($envelopes);
}
}
+3 -3
View File
@@ -29,7 +29,7 @@ final class FilterBuilder
private $maxResults;
/**
* @param array $orderings
* @param array<string, string> $orderings
*
* @return self
*/
@@ -51,11 +51,11 @@ final class FilterBuilder
}
/**
* @param $criteria
* @param array $criteria
*
* @return $this
*/
public function withCriteria($criteria)
public function withCriteria(array $criteria)
{
$criteriaBuilder = new CriteriaBuilder($this, $criteria);
$criteriaBuilder->build();
+9
View File
@@ -2,6 +2,15 @@
namespace Flasher\Prime\Filter;
use Flasher\Prime\Envelope;
interface FilterInterface
{
/**
* @param Envelope[] $envelopes
* @param array $criteria
*
* @return array
*/
public function filter(array $envelopes, array $criteria);
}
-16
View File
@@ -1,16 +0,0 @@
<?php
namespace Flasher\Prime\Filter;
use Flasher\Prime\Manager\AbstractManager;
/**
* @mixin FilterInterface
*/
final class FilterManager extends AbstractManager implements FilterManagerInterface
{
protected function getDefaultDriver()
{
return $this->config->get('default_filter', 'default');
}
}
@@ -1,27 +0,0 @@
<?php
namespace Flasher\Prime\Filter;
interface FilterManagerInterface
{
/**
* Get a driver instance.
*
* @param string|null $alias
*
* @return FilterInterface
*
* @throws \InvalidArgumentException
*/
public function make($alias = null);
/**
* Register a custom driver creator.
*
* @param string $alias
* @param \Closure|FilterInterface $driver
*
* @return $this
*/
public function addDriver($alias, $driver);
}
@@ -14,7 +14,7 @@ final class AndSpecification implements SpecificationInterface
/**
* @param SpecificationInterface|SpecificationInterface[] $specifications
*/
public function __construct($specifications = array())
public function __construct($specifications)
{
$specifications = is_array($specifications) ? $specifications : func_get_args();
@@ -14,7 +14,7 @@ final class OrSpecification implements SpecificationInterface
/**
* @param SpecificationInterface|SpecificationInterface[] $specifications
*/
public function __construct($specifications = array())
public function __construct($specifications)
{
$specifications = is_array($specifications) ? $specifications : func_get_args();
+64 -7
View File
@@ -2,16 +2,73 @@
namespace Flasher\Prime;
use Flasher\Prime\Manager\AbstractManager;
use Flasher\Prime\Notification\NotificationBuilderInterface;
use Flasher\Prime\Config\ConfigInterface;
use Flasher\Prime\Factory\FactoryInterface;
/**
* @mixin NotificationBuilderInterface
*/
final class Flasher extends AbstractManager implements FlasherInterface
final class Flasher implements FlasherInterface
{
public function getDefaultDriver()
/**
* The array of created notification "factories".
*
* @var array<string, object>
*/
private $factories = array();
/**
* @var ConfigInterface
*/
private $config;
/**
* @param ConfigInterface $config
*/
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
/**
* @inheritDoc
*/
public function create($alias = null)
{
$alias = $alias ?: $this->getDefaultFactory();
if (!isset($this->factories[$alias])) {
throw new \InvalidArgumentException(sprintf('Factory [%s] not supported.', $alias));
}
return $this->factories[$alias];
}
/**
* @inheritDoc
*/
public function addFactory($alias, FactoryInterface $factory)
{
$this->factories[$alias] = $factory;
return $this;
}
/**
* @return string|null
*/
private function getDefaultFactory()
{
return $this->config->get('default');
}
/**
* Dynamically call the default factory instance.
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, array $parameters)
{
return call_user_func_array(array($this->make(), $method), $parameters);
}
}
+5 -5
View File
@@ -2,7 +2,7 @@
namespace Flasher\Prime;
use Flasher\Prime\Factory\FlasherFactoryInterface;
use Flasher\Prime\Factory\FactoryInterface;
use Flasher\Prime\Notification\NotificationBuilderInterface;
/**
@@ -15,19 +15,19 @@ interface FlasherInterface
*
* @param string|null $alias
*
* @return FlasherFactoryInterface
* @return FactoryInterface
*
* @throws \InvalidArgumentException
*/
public function make($alias = null);
public function create($alias = null);
/**
* Register a custom driver creator.
*
* @param string
* @param \Closure|FlasherFactoryInterface $driver
* @param FactoryInterface $factory
*
* @return $this
*/
public function addDriver($alias, $driver);
public function addFactory($alias, FactoryInterface $factory);
}
-85
View File
@@ -1,85 +0,0 @@
<?php
namespace Flasher\Prime\Manager;
use InvalidArgumentException;
use Flasher\Prime\Config\ConfigInterface;
abstract class AbstractManager
{
/**
* The array of created "drivers".
*
* @var array<string, object>
*/
protected $drivers = array();
/**
* @var ConfigInterface
*/
protected $config;
/**
* @param ConfigInterface $config
*/
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
/**
* Get a driver instance.
*
* @param string|null $alias
*
* @return object
*
* @throws \InvalidArgumentException
*/
public function make($alias = null)
{
$alias = $alias ?: $this->getDefaultDriver();
if (!isset($this->drivers[$alias])) {
throw new InvalidArgumentException(sprintf('Driver [%s] not supported.', $alias));
}
return $this->drivers[$alias];
}
/**
* Register a custom driver creator.
*
* @param string $alias
* @param \Closure|object $driver
*
* @return $this
*/
public function addDriver($alias, $driver)
{
$this->drivers[$alias] = $driver;
return $this;
}
/**
* @return string|null
*/
protected function getDefaultDriver()
{
return null;
}
/**
* Dynamically call the default driver instance.
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, array $parameters)
{
return call_user_func_array(array($this->make(), $method), $parameters);
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ class Notification implements NotificationInterface
/**
* @var string
*/
protected $type = self::TYPE_SUCCESS;
protected $type = self::TYPE_INFO;
/**
* @var array<string, mixed>
+11 -12
View File
@@ -3,13 +3,12 @@
namespace Flasher\Prime\Notification;
use Flasher\Prime\Envelope;
use Flasher\Prime\EventDispatcher\Event\PostBuildEvent;
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
use Flasher\Prime\Stamp\DelayStamp;
use Flasher\Prime\Stamp\HandlerStamp;
use Flasher\Prime\Stamp\HopsStamp;
use Flasher\Prime\Stamp\PriorityStamp;
use Flasher\Prime\Stamp\StampInterface;
use Flasher\Prime\Storage\StorageManagerInterface;
class NotificationBuilder implements NotificationBuilderInterface
{
@@ -19,18 +18,18 @@ class NotificationBuilder implements NotificationBuilderInterface
protected $envelope;
/**
* @var EventDispatcherInterface
* @var StorageManagerInterface
*/
protected $eventDispatcher;
protected $storageManager;
/**
* @param EventDispatcherInterface $eventDispatcher
* @param NotificationInterface $notification
* @param string $handler
* @param StorageManagerInterface $storageManager
* @param NotificationInterface $notification
* @param string $handler
*/
public function __construct(EventDispatcherInterface $eventDispatcher, NotificationInterface $notification, $handler)
public function __construct(StorageManagerInterface $storageManager, NotificationInterface $notification, $handler)
{
$this->eventDispatcher = $eventDispatcher;
$this->storageManager = $storageManager;
$this->envelope = Envelope::wrap($notification);
$this->handler($handler);
}
@@ -103,9 +102,9 @@ class NotificationBuilder implements NotificationBuilderInterface
$this->with($stamps);
}
$event = new PostBuildEvent($this->getEnvelope());
$this->storageManager->add($this->getEnvelope());
return $this->eventDispatcher->dispatch($event);
return $this->getEnvelope();
}
/**
@@ -218,7 +217,7 @@ class NotificationBuilder implements NotificationBuilderInterface
public function keep()
{
$hopsStamp = $this->envelope->get('Flasher\Prime\Stamp\HopsStamp');
$amount = $hopsStamp instanceof HopsStamp ? $hopsStamp->getAmount() : 1;
$amount = $hopsStamp instanceof HopsStamp ? $hopsStamp->getAmount() : 1;
$this->envelope->withStamp(new HopsStamp($amount + 1));
@@ -1,13 +0,0 @@
<?php
namespace Flasher\Prime\Presenter;
interface PresenterInterface
{
/**
* @param string $criteria
*
* @return string
*/
public function render($criteria = 'default');
}
@@ -1,6 +1,6 @@
<?php
namespace Flasher\Prime\Presenter;
namespace Flasher\Prime\Renderer;
use Flasher\Prime\Config\ConfigInterface;
use Flasher\Prime\Envelope;
@@ -8,7 +8,7 @@ use Flasher\Prime\EventDispatcher\Event\FilterEvent;
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
use Flasher\Prime\Storage\StorageManagerInterface;
final class Presenter implements PresenterInterface
final class Renderer implements RendererInterface
{
/**
* @var StorageManagerInterface
@@ -30,19 +30,22 @@ final class Presenter implements PresenterInterface
* @param EventDispatcherInterface $eventDispatcher
* @param ConfigInterface $config
*/
public function __construct(StorageManagerInterface $storageManager, EventDispatcherInterface $eventDispatcher, ConfigInterface $config)
{
public function __construct(
StorageManagerInterface $storageManager,
EventDispatcherInterface $eventDispatcher,
ConfigInterface $config
) {
$this->storageManager = $storageManager;
$this->eventDispatcher = $eventDispatcher;
$this->config = $config;
}
/**
* @param string|array $criteria
* @param array $criteria
*
* @return array
*/
public function render($criteria = null)
public function render(array $criteria = array())
{
$envelopes = $this->getEnvelopes($criteria);
@@ -63,11 +66,11 @@ final class Presenter implements PresenterInterface
}
/**
* @param string|array $criteria
* @param array $criteria
*
* @return Envelope[]
*/
protected function getEnvelopes($criteria = array())
private function getEnvelopes(array $criteria)
{
$envelopes = $this->storageManager->all();
@@ -82,22 +85,9 @@ final class Presenter implements PresenterInterface
*
* @return string[]
*/
protected function getStyles($envelopes)
private function getStyles(array $envelopes)
{
$files = $this->config->get('styles', array());
$handlers = array();
foreach ($envelopes as $envelope) {
$handler = $envelope->get('Flasher\Prime\Stamp\HandlerStamp')->getHandler();
if (in_array($handler, $handlers)) {
continue;
}
$handlers[] = $handler;
$files = array_merge($files, $this->config->get(sprintf('adapters.%s.styles', $handler), array()));
}
return array_values(array_filter(array_unique($files)));
return $this->getAssets('styles', $envelopes);
}
/**
@@ -105,22 +95,9 @@ final class Presenter implements PresenterInterface
*
* @return string[]
*/
protected function getScripts($envelopes)
private function getScripts(array $envelopes)
{
$files = $this->config->get('scripts', array());
$handlers = array();
foreach ($envelopes as $envelope) {
$handler = $envelope->get('Flasher\Prime\Stamp\HandlerStamp')->getHandler();
if (in_array($handler, $handlers)) {
continue;
}
$handlers[] = $handler;
$files = array_merge($files, $this->config->get(sprintf('adapters.%s.scripts', $handler), array()));
}
return array_values(array_filter(array_unique($files)));
return $this->getAssets('scripts', $envelopes);
}
/**
@@ -128,9 +105,9 @@ final class Presenter implements PresenterInterface
*
* @return string[]
*/
protected function getOptions($envelopes)
private function getOptions(array $envelopes)
{
$options = array();
$options = array();
$handlers = array();
foreach ($envelopes as $envelope) {
@@ -143,7 +120,7 @@ final class Presenter implements PresenterInterface
$options[$handler] = $this->config->get(sprintf('adapters.%s.options', $handler), array());
}
return array_values(array_filter(array_unique($options)));
return array_filter($options);
}
/**
@@ -151,15 +128,37 @@ final class Presenter implements PresenterInterface
*
* @return array[]
*/
public function getNotifications($envelopes)
private function getNotifications(array $envelopes)
{
$notifications = array();
return array_map(function (Envelope $envelope) {
return array(
'handler' => $envelope->get('Flasher\Prime\Stamp\HandlerStamp')->getHandler(),
'notification' => $envelope->toArray(),
);
}, $envelopes);
}
foreach ($envelopes as $index => $envelope) {
$notifications[$index] = $envelope->toArray();
$notifications[$index]['library'] = $envelope->get('Flasher\Prime\Stamp\HandlerStamp')->getHandler();
/**
* @param string $keyword
* @param Envelope[] $envelopes
*
* @return string[]
*/
private function getAssets($keyword, $envelopes)
{
$files = $this->config->get($keyword, array());
$handlers = array();
foreach ($envelopes as $envelope) {
$handler = $envelope->get('Flasher\Prime\Stamp\HandlerStamp')->getHandler();
if (in_array($handler, $handlers)) {
continue;
}
$handlers[] = $handler;
$files = array_merge($files, $this->config->get(sprintf('adapters.%s.%s', $handler, $keyword), array()));
}
return $notifications;
return array_values(array_filter(array_unique($files)));
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Flasher\Prime\Renderer;
interface RendererInterface
{
/**
* @param array $criteria
*
* @return string
*/
public function render(array $criteria = array());
}
+1 -1
View File
@@ -32,7 +32,7 @@ final class CreatedAtStamp implements StampInterface, OrderableStampInterface
}
/**
* @param OrderableStampInterface $orderable
* @param mixed $orderable
*
* @return int
*/
+1 -1
View File
@@ -5,7 +5,7 @@ namespace Flasher\Prime\Stamp;
interface OrderableStampInterface
{
/**
* @param OrderableStampInterface $orderable
* @param mixed $orderable
*
* @return int
*/
+1 -1
View File
@@ -26,7 +26,7 @@ final class PriorityStamp implements StampInterface, OrderableStampInterface
}
/**
* @param OrderableStampInterface $orderable
* @param mixed $orderable
*
* @return int
*/
+6 -6
View File
@@ -2,10 +2,10 @@
namespace Flasher\Prime\Storage;
use Flasher\Prime\EventDispatcher\Event\PersistEvent;
use Flasher\Prime\EventDispatcher\Event\RemoveEvent;
use Flasher\Prime\EventDispatcher\Event\UpdateEvent;
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
use Flasher\Prime\EventDispatcher\Event\PrePersistEvent;
use Flasher\Prime\EventDispatcher\Event\PreRemoveEvent;
use Flasher\Prime\EventDispatcher\Event\PreUpdateEvent;
final class StorageManager implements StorageManagerInterface
{
@@ -44,7 +44,7 @@ final class StorageManager implements StorageManagerInterface
{
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
$event = new PrePersistEvent($envelopes);
$event = new PersistEvent($envelopes);
$this->eventDispatcher->dispatch($event);
$this->storage->add($event->getEnvelopes());
@@ -57,7 +57,7 @@ final class StorageManager implements StorageManagerInterface
{
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
$event = new PreUpdateEvent($envelopes);
$event = new UpdateEvent($envelopes);
$this->eventDispatcher->dispatch($event);
$this->storage->update($event->getEnvelopes());
@@ -70,7 +70,7 @@ final class StorageManager implements StorageManagerInterface
{
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
$event = new PreRemoveEvent($envelopes);
$event = new RemoveEvent($envelopes);
$this->eventDispatcher->dispatch($event);
$this->storage->remove($event->getEnvelopes());
@@ -3,11 +3,7 @@
namespace Flasher\Prime\Storage;
use Flasher\Prime\Envelope;
use Flasher\Prime\Filter\FilterInterface;
/**
* @mixin FilterInterface
*/
interface StorageManagerInterface
{
/**
+5 -5
View File
@@ -15,7 +15,7 @@ final class ManagerTest extends TestCase
->willReturn('default_notifier');
$manager = new Flasher($config);
$this->assertEquals('default_notifier', $manager->getDefaultDriver());
$this->assertEquals('default_notifier', $manager->getDefaultFactory());
}
public function testMakeDriver()
@@ -27,9 +27,9 @@ final class ManagerTest extends TestCase
$manager = new Flasher($config);
$producer = $this->getMockBuilder('Flasher\Prime\Factory\FlasherFactoryInterface')->getMock();
$producer = $this->getMockBuilder('Flasher\Prime\Factory\FactoryInterface')->getMock();
$producer->method('supports')->willReturn(true);
$manager->addDriver($producer);
$manager->addFactory($producer);
$this->assertSame($producer, $manager->make('fake'));
}
@@ -45,8 +45,8 @@ final class ManagerTest extends TestCase
$manager = new Flasher($config);
$producer = $this->getMockBuilder('Flasher\Prime\Factory\FlasherFactoryInterface')->getMock();
$manager->addDriver($producer);
$producer = $this->getMockBuilder('Flasher\Prime\Factory\FactoryInterface')->getMock();
$manager->addFactory($producer);
$manager->make('test_driver');
}
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
@@ -47,7 +47,7 @@ class Laravel implements ServiceProviderInterface
$this->app->alias('flasher.renderer.sweet_alert', 'Flasher\SweetAlert\Prime\SweetAlertRenderer');
$this->app->extend('flasher', function (Flasher $manager, Container $app) {
$manager->addDriver($app['flasher.factory.sweet_alert']);
$manager->addFactory($app['flasher.factory.sweet_alert']);
return $manager;
});
@@ -21,7 +21,7 @@ class FlasherSweetAlertServiceProviderTest extends TestCase
$extensions = $property->getValue($flasher);
$this->assertCount(1, $extensions);
$this->assertInstanceOf('Flasher\Prime\Factory\FlasherFactoryInterface', $extensions[0]);
$this->assertInstanceOf('Flasher\Prime\Factory\FactoryInterface', $extensions[0]);
}
public function testConfigSweetAlertInjectedInGlobalNotifyConfig()
+1 -1
View File
@@ -19,7 +19,7 @@ final class SweetAlertFactory extends AbstractFactory
*/
public function createNotificationBuilder()
{
return new SweetAlertBuilder($this->getEventDispatcher(), $this->createNotification(), 'sweet_alert');
return new SweetAlertBuilder($this->getStorageManager(), $this->createNotification(), 'sweet_alert');
}
/**
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
@@ -2,7 +2,7 @@
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\PresenterManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -4,7 +4,7 @@ namespace Flasher\Symfony\EventListener;
use Flasher\Prime\Config\ConfigInterface;
use Flasher\Prime\FlasherInterface;
use Flasher\Prime\Presenter\Adapter\HtmlPresenter;
use Flasher\Prime\Renderer\Adapter\HtmlPresenter;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Flasher\Symfony\Twig;
use Flasher\Prime\Presenter\Adapter\HtmlPresenter;
use Flasher\Prime\Renderer\Adapter\HtmlPresenter;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));
@@ -47,7 +47,7 @@ class Laravel implements ServiceProviderInterface
$this->app->alias('flasher.renderer.toastr', 'Flasher\Toastr\Prime\ToastrRenderer');
$this->app->extend('flasher', function (Flasher $flasher, Container $app) {
$flasher->addDriver($app['flasher.factory.toastr']);
$flasher->addFactory($app['flasher.factory.toastr']);
return $flasher;
});
@@ -21,7 +21,7 @@ class FlasherToastrServiceProviderTest extends TestCase
$extensions = $property->getValue($flasher);
$this->assertCount(1, $extensions);
$this->assertInstanceOf('Flasher\Prime\Factory\FlasherFactoryInterface', $extensions[0]);
$this->assertInstanceOf('Flasher\Prime\Factory\FactoryInterface', $extensions[0]);
}
public function testConfigToastrInjectedInGlobalNotifyConfig()
+1 -1
View File
@@ -71,7 +71,7 @@ final class ToastrFactory extends AbstractFactory
*/
public function createNotificationBuilder()
{
return new ToastrBuilder($this->getEventDispatcher(), $this->createNotification(), 'toastr');
return new ToastrBuilder($this->getStorageManager(), $this->createNotification(), 'toastr');
}
/**
-11
View File
@@ -1,14 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Envelope;
use Flasher\Prime\Flasher;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
override(Envelope::get(), type(0));
override(Flasher::make(''), map(['' => '@']));
override(RendererManager::make(''), map(['' => '@']));
override(PresenterManager::make(''), map(['' => '@']));