From fa21d27ccd97c9227e3dc20bade60989ecf53e1b Mon Sep 17 00:00:00 2001 From: Khoubza Younes Date: Tue, 8 Dec 2020 22:33:56 +0100 Subject: [PATCH] remove middelawares and delete renderer and rename presenter to renderer --- src/Laravel/.phpstorm.meta.php | 11 --- src/Laravel/Middleware/SessionMiddleware.php | 2 +- .../ServiceProvider/Providers/Laravel.php | 20 ++-- src/Noty/Laravel/.phpstorm.meta.php | 11 --- .../ServiceProvider/Providers/Laravel.php | 2 +- .../Tests/FlasherNotyServiceProviderTest.php | 2 +- src/Noty/Prime/NotyFactory.php | 2 +- src/Noty/Symfony/.phpstorm.meta.php | 11 --- src/Notyf/Laravel/.phpstorm.meta.php | 11 --- .../ServiceProvider/Providers/Laravel.php | 2 +- .../Tests/FlasherNotyfServiceProviderTest.php | 2 +- src/Notyf/Prime/NotyfFactory.php | 2 +- src/Notyf/Symfony/.phpstorm.meta.php | 11 --- src/Pnotify/Laravel/.phpstorm.meta.php | 11 --- .../ServiceProvider/Providers/Laravel.php | 2 +- .../FlasherPnotifyServiceProviderTest.php | 2 +- src/Pnotify/Prime/PnotifyFactory.php | 2 +- src/Pnotify/Symfony/.phpstorm.meta.php | 11 --- src/Prime/.phpstorm.meta.php | 18 ++-- src/Prime/Envelope.php | 16 ++-- .../{PostBuildEvent.php => BuildEvent.php} | 2 +- .../EventDispatcher/Event/FilterEvent.php | 12 +-- .../{PreRemoveEvent.php => PersistEvent.php} | 2 +- .../{PreUpdateEvent.php => RemoveEvent.php} | 2 +- .../{PrePersistEvent.php => UpdateEvent.php} | 2 +- src/Prime/EventDispatcher/EventDispatcher.php | 2 +- .../EventListener/FilterListener.php | 47 ++++++++++ .../EventListener/PostBuildListener.php | 8 +- .../EventListener/PostFilterListener.php | 59 ------------ ...PersistListener.php => StampsListener.php} | 14 ++- src/Prime/Factory/AbstractFactory.php | 26 +++--- ...toryInterface.php => FactoryInterface.php} | 2 +- src/Prime/Filter/CriteriaBuilder.php | 6 +- src/Prime/Filter/DefaultFilter.php | 32 ------- src/Prime/Filter/Filter.php | 27 ++++++ src/Prime/Filter/FilterBuilder.php | 6 +- src/Prime/Filter/FilterInterface.php | 9 ++ src/Prime/Filter/FilterManager.php | 16 ---- src/Prime/Filter/FilterManagerInterface.php | 27 ------ .../Filter/Specification/AndSpecification.php | 2 +- .../Filter/Specification/OrSpecification.php | 2 +- src/Prime/Flasher.php | 71 ++++++++++++-- src/Prime/FlasherInterface.php | 10 +- src/Prime/Manager/AbstractManager.php | 85 ----------------- src/Prime/Notification/Notification.php | 2 +- .../Notification/NotificationBuilder.php | 23 +++-- src/Prime/Presenter/PresenterInterface.php | 13 --- .../Presenter.php => Renderer/Renderer.php} | 93 +++++++++---------- src/Prime/Renderer/RendererInterface.php | 13 +++ src/Prime/Stamp/CreatedAtStamp.php | 2 +- src/Prime/Stamp/OrderableStampInterface.php | 2 +- src/Prime/Stamp/PriorityStamp.php | 2 +- src/Prime/Storage/StorageManager.php | 12 +-- src/Prime/Storage/StorageManagerInterface.php | 4 - src/Prime/Tests/Manager/ManagerTest.php | 10 +- src/SweetAlert/Laravel/.phpstorm.meta.php | 11 --- .../ServiceProvider/Providers/Laravel.php | 2 +- .../FlasherSweetAlertServiceProviderTest.php | 2 +- src/SweetAlert/Prime/SweetAlertFactory.php | 2 +- src/SweetAlert/Symfony/.phpstorm.meta.php | 11 --- src/Symfony/.phpstorm.meta.php | 11 --- .../Compiler/PresenterCompilerPass.php | 2 +- src/Symfony/EventListener/SessionListener.php | 2 +- src/Symfony/Twig/FlasherTwigExtension.php | 2 +- src/Toastr/Laravel/.phpstorm.meta.php | 11 --- .../ServiceProvider/Providers/Laravel.php | 2 +- .../FlasherToastrServiceProviderTest.php | 2 +- src/Toastr/Prime/ToastrFactory.php | 2 +- src/Toastr/Symfony/.phpstorm.meta.php | 11 --- 69 files changed, 327 insertions(+), 544 deletions(-) rename src/Prime/EventDispatcher/Event/{PostBuildEvent.php => BuildEvent.php} (95%) rename src/Prime/EventDispatcher/Event/{PreRemoveEvent.php => PersistEvent.php} (95%) rename src/Prime/EventDispatcher/Event/{PreUpdateEvent.php => RemoveEvent.php} (95%) rename src/Prime/EventDispatcher/Event/{PrePersistEvent.php => UpdateEvent.php} (95%) create mode 100644 src/Prime/EventDispatcher/EventListener/FilterListener.php delete mode 100644 src/Prime/EventDispatcher/EventListener/PostFilterListener.php rename src/Prime/EventDispatcher/EventListener/{PrePersistListener.php => StampsListener.php} (76%) rename src/Prime/Factory/{FlasherFactoryInterface.php => FactoryInterface.php} (88%) delete mode 100644 src/Prime/Filter/DefaultFilter.php create mode 100644 src/Prime/Filter/Filter.php delete mode 100644 src/Prime/Filter/FilterManager.php delete mode 100644 src/Prime/Filter/FilterManagerInterface.php delete mode 100644 src/Prime/Manager/AbstractManager.php delete mode 100644 src/Prime/Presenter/PresenterInterface.php rename src/Prime/{Presenter/Presenter.php => Renderer/Renderer.php} (63%) create mode 100644 src/Prime/Renderer/RendererInterface.php diff --git a/src/Laravel/.phpstorm.meta.php b/src/Laravel/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Laravel/.phpstorm.meta.php +++ b/src/Laravel/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Laravel/Middleware/SessionMiddleware.php b/src/Laravel/Middleware/SessionMiddleware.php index c2f9c70d..b4d0e193 100644 --- a/src/Laravel/Middleware/SessionMiddleware.php +++ b/src/Laravel/Middleware/SessionMiddleware.php @@ -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; diff --git a/src/Laravel/ServiceProvider/Providers/Laravel.php b/src/Laravel/ServiceProvider/Providers/Laravel.php index 14dc151d..d27eb69a 100644 --- a/src/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Laravel/ServiceProvider/Providers/Laravel.php @@ -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'); diff --git a/src/Noty/Laravel/.phpstorm.meta.php b/src/Noty/Laravel/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Noty/Laravel/.phpstorm.meta.php +++ b/src/Noty/Laravel/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Noty/Laravel/ServiceProvider/Providers/Laravel.php b/src/Noty/Laravel/ServiceProvider/Providers/Laravel.php index 11c1bc88..3e9efde1 100644 --- a/src/Noty/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Noty/Laravel/ServiceProvider/Providers/Laravel.php @@ -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; }); diff --git a/src/Noty/Laravel/Tests/FlasherNotyServiceProviderTest.php b/src/Noty/Laravel/Tests/FlasherNotyServiceProviderTest.php index 24aca4b5..1e36d8f7 100644 --- a/src/Noty/Laravel/Tests/FlasherNotyServiceProviderTest.php +++ b/src/Noty/Laravel/Tests/FlasherNotyServiceProviderTest.php @@ -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() diff --git a/src/Noty/Prime/NotyFactory.php b/src/Noty/Prime/NotyFactory.php index ff72e672..44bdeb2e 100644 --- a/src/Noty/Prime/NotyFactory.php +++ b/src/Noty/Prime/NotyFactory.php @@ -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'); } /** diff --git a/src/Noty/Symfony/.phpstorm.meta.php b/src/Noty/Symfony/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Noty/Symfony/.phpstorm.meta.php +++ b/src/Noty/Symfony/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Notyf/Laravel/.phpstorm.meta.php b/src/Notyf/Laravel/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Notyf/Laravel/.phpstorm.meta.php +++ b/src/Notyf/Laravel/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php b/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php index cc112cf4..61cb46ef 100644 --- a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php @@ -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; }); diff --git a/src/Notyf/Laravel/Tests/FlasherNotyfServiceProviderTest.php b/src/Notyf/Laravel/Tests/FlasherNotyfServiceProviderTest.php index 76acdd0c..efaf5959 100644 --- a/src/Notyf/Laravel/Tests/FlasherNotyfServiceProviderTest.php +++ b/src/Notyf/Laravel/Tests/FlasherNotyfServiceProviderTest.php @@ -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() diff --git a/src/Notyf/Prime/NotyfFactory.php b/src/Notyf/Prime/NotyfFactory.php index f5bf6fa1..f8e4149b 100644 --- a/src/Notyf/Prime/NotyfFactory.php +++ b/src/Notyf/Prime/NotyfFactory.php @@ -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'); } /** diff --git a/src/Notyf/Symfony/.phpstorm.meta.php b/src/Notyf/Symfony/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Notyf/Symfony/.phpstorm.meta.php +++ b/src/Notyf/Symfony/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Pnotify/Laravel/.phpstorm.meta.php b/src/Pnotify/Laravel/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Pnotify/Laravel/.phpstorm.meta.php +++ b/src/Pnotify/Laravel/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel.php b/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel.php index 07b02394..23682428 100644 --- a/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel.php @@ -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; }); diff --git a/src/Pnotify/Laravel/Tests/FlasherPnotifyServiceProviderTest.php b/src/Pnotify/Laravel/Tests/FlasherPnotifyServiceProviderTest.php index 6c086cb6..f9093120 100644 --- a/src/Pnotify/Laravel/Tests/FlasherPnotifyServiceProviderTest.php +++ b/src/Pnotify/Laravel/Tests/FlasherPnotifyServiceProviderTest.php @@ -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() diff --git a/src/Pnotify/Prime/PnotifyFactory.php b/src/Pnotify/Prime/PnotifyFactory.php index f9ae4a6b..cb44ec3c 100644 --- a/src/Pnotify/Prime/PnotifyFactory.php +++ b/src/Pnotify/Prime/PnotifyFactory.php @@ -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'); } /** diff --git a/src/Pnotify/Symfony/.phpstorm.meta.php b/src/Pnotify/Symfony/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Pnotify/Symfony/.phpstorm.meta.php +++ b/src/Pnotify/Symfony/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Prime/.phpstorm.meta.php b/src/Prime/.phpstorm.meta.php index c31c2a82..d9b2b73d 100644 --- a/src/Prime/.phpstorm.meta.php +++ b/src/Prime/.phpstorm.meta.php @@ -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')); diff --git a/src/Prime/Envelope.php b/src/Prime/Envelope.php index d5a432dd..f0be3dbf 100644 --- a/src/Prime/Envelope.php +++ b/src/Prime/Envelope.php @@ -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(); diff --git a/src/Prime/EventDispatcher/Event/PostBuildEvent.php b/src/Prime/EventDispatcher/Event/BuildEvent.php similarity index 95% rename from src/Prime/EventDispatcher/Event/PostBuildEvent.php rename to src/Prime/EventDispatcher/Event/BuildEvent.php index af08e80b..a3f853f0 100644 --- a/src/Prime/EventDispatcher/Event/PostBuildEvent.php +++ b/src/Prime/EventDispatcher/Event/BuildEvent.php @@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event; use Flasher\Prime\Envelope; -final class PostBuildEvent +final class BuildEvent { /** * @var Envelope diff --git a/src/Prime/EventDispatcher/Event/FilterEvent.php b/src/Prime/EventDispatcher/Event/FilterEvent.php index db8b480d..1a89b245 100644 --- a/src/Prime/EventDispatcher/Event/FilterEvent.php +++ b/src/Prime/EventDispatcher/Event/FilterEvent.php @@ -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; } diff --git a/src/Prime/EventDispatcher/Event/PreRemoveEvent.php b/src/Prime/EventDispatcher/Event/PersistEvent.php similarity index 95% rename from src/Prime/EventDispatcher/Event/PreRemoveEvent.php rename to src/Prime/EventDispatcher/Event/PersistEvent.php index 1abb4db2..9e0948f3 100644 --- a/src/Prime/EventDispatcher/Event/PreRemoveEvent.php +++ b/src/Prime/EventDispatcher/Event/PersistEvent.php @@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event; use Flasher\Prime\Envelope; -final class PreRemoveEvent +final class PersistEvent { /** * @var Envelope[] diff --git a/src/Prime/EventDispatcher/Event/PreUpdateEvent.php b/src/Prime/EventDispatcher/Event/RemoveEvent.php similarity index 95% rename from src/Prime/EventDispatcher/Event/PreUpdateEvent.php rename to src/Prime/EventDispatcher/Event/RemoveEvent.php index 27d142d3..b89dbccb 100644 --- a/src/Prime/EventDispatcher/Event/PreUpdateEvent.php +++ b/src/Prime/EventDispatcher/Event/RemoveEvent.php @@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event; use Flasher\Prime\Envelope; -final class PreUpdateEvent +final class RemoveEvent { /** * @var Envelope[] diff --git a/src/Prime/EventDispatcher/Event/PrePersistEvent.php b/src/Prime/EventDispatcher/Event/UpdateEvent.php similarity index 95% rename from src/Prime/EventDispatcher/Event/PrePersistEvent.php rename to src/Prime/EventDispatcher/Event/UpdateEvent.php index f7a2ddbd..2ebb2b31 100644 --- a/src/Prime/EventDispatcher/Event/PrePersistEvent.php +++ b/src/Prime/EventDispatcher/Event/UpdateEvent.php @@ -4,7 +4,7 @@ namespace Flasher\Prime\EventDispatcher\Event; use Flasher\Prime\Envelope; -final class PrePersistEvent +final class UpdateEvent { /** * @var Envelope[] diff --git a/src/Prime/EventDispatcher/EventDispatcher.php b/src/Prime/EventDispatcher/EventDispatcher.php index 03c78cf2..b0c5a45a 100644 --- a/src/Prime/EventDispatcher/EventDispatcher.php +++ b/src/Prime/EventDispatcher/EventDispatcher.php @@ -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()) { diff --git a/src/Prime/EventDispatcher/EventListener/FilterListener.php b/src/Prime/EventDispatcher/EventListener/FilterListener.php new file mode 100644 index 00000000..cffd6d7f --- /dev/null +++ b/src/Prime/EventDispatcher/EventListener/FilterListener.php @@ -0,0 +1,47 @@ +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'; + } +} diff --git a/src/Prime/EventDispatcher/EventListener/PostBuildListener.php b/src/Prime/EventDispatcher/EventListener/PostBuildListener.php index 4bc39ef4..200c5a01 100644 --- a/src/Prime/EventDispatcher/EventListener/PostBuildListener.php +++ b/src/Prime/EventDispatcher/EventListener/PostBuildListener.php @@ -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'; } } diff --git a/src/Prime/EventDispatcher/EventListener/PostFilterListener.php b/src/Prime/EventDispatcher/EventListener/PostFilterListener.php deleted file mode 100644 index 14b4d0f8..00000000 --- a/src/Prime/EventDispatcher/EventListener/PostFilterListener.php +++ /dev/null @@ -1,59 +0,0 @@ -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'; - } -} diff --git a/src/Prime/EventDispatcher/EventListener/PrePersistListener.php b/src/Prime/EventDispatcher/EventListener/StampsListener.php similarity index 76% rename from src/Prime/EventDispatcher/EventListener/PrePersistListener.php rename to src/Prime/EventDispatcher/EventListener/StampsListener.php index 1ac54236..6d115fd0 100644 --- a/src/Prime/EventDispatcher/EventListener/PrePersistListener.php +++ b/src/Prime/EventDispatcher/EventListener/StampsListener.php @@ -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', + ); } } diff --git a/src/Prime/Factory/AbstractFactory.php b/src/Prime/Factory/AbstractFactory.php index 37ad30ef..0d286937 100644 --- a/src/Prime/Factory/AbstractFactory.php +++ b/src/Prime/Factory/AbstractFactory.php @@ -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; } } diff --git a/src/Prime/Factory/FlasherFactoryInterface.php b/src/Prime/Factory/FactoryInterface.php similarity index 88% rename from src/Prime/Factory/FlasherFactoryInterface.php rename to src/Prime/Factory/FactoryInterface.php index 1a85019d..3942cf82 100644 --- a/src/Prime/Factory/FlasherFactoryInterface.php +++ b/src/Prime/Factory/FactoryInterface.php @@ -7,7 +7,7 @@ use Flasher\Prime\Notification\NotificationBuilderInterface; /** * @mixin NotificationBuilderInterface */ -interface FlasherFactoryInterface +interface FactoryInterface { /** * @return NotificationBuilderInterface diff --git a/src/Prime/Filter/CriteriaBuilder.php b/src/Prime/Filter/CriteriaBuilder.php index c2648147..59ac6a16 100644 --- a/src/Prime/Filter/CriteriaBuilder.php +++ b/src/Prime/Filter/CriteriaBuilder.php @@ -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; diff --git a/src/Prime/Filter/DefaultFilter.php b/src/Prime/Filter/DefaultFilter.php deleted file mode 100644 index 84b0fc04..00000000 --- a/src/Prime/Filter/DefaultFilter.php +++ /dev/null @@ -1,32 +0,0 @@ -filterBuilder = $filterBuilder; - } - - /** - * @param Envelope[] $envelopes - * @param array $criteria - * - * @return array - */ - public function filter($envelopes, $criteria = array()) - { - return $this->filterBuilder->withCriteria($criteria)->filter($envelopes); - } -} diff --git a/src/Prime/Filter/Filter.php b/src/Prime/Filter/Filter.php new file mode 100644 index 00000000..d8e2024e --- /dev/null +++ b/src/Prime/Filter/Filter.php @@ -0,0 +1,27 @@ +filterBuilder = $filterBuilder ?: new FilterBuilder(); + } + + /** + * @inheritDoc + */ + public function filter(array $envelopes, array $criteria) + { + return $this->filterBuilder->withCriteria($criteria)->filter($envelopes); + } +} diff --git a/src/Prime/Filter/FilterBuilder.php b/src/Prime/Filter/FilterBuilder.php index 3e4c9fe5..b4fab68d 100644 --- a/src/Prime/Filter/FilterBuilder.php +++ b/src/Prime/Filter/FilterBuilder.php @@ -29,7 +29,7 @@ final class FilterBuilder private $maxResults; /** - * @param array $orderings + * @param array $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(); diff --git a/src/Prime/Filter/FilterInterface.php b/src/Prime/Filter/FilterInterface.php index ccf7bd50..06758382 100644 --- a/src/Prime/Filter/FilterInterface.php +++ b/src/Prime/Filter/FilterInterface.php @@ -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); } diff --git a/src/Prime/Filter/FilterManager.php b/src/Prime/Filter/FilterManager.php deleted file mode 100644 index a15b6861..00000000 --- a/src/Prime/Filter/FilterManager.php +++ /dev/null @@ -1,16 +0,0 @@ -config->get('default_filter', 'default'); - } -} diff --git a/src/Prime/Filter/FilterManagerInterface.php b/src/Prime/Filter/FilterManagerInterface.php deleted file mode 100644 index 830e572c..00000000 --- a/src/Prime/Filter/FilterManagerInterface.php +++ /dev/null @@ -1,27 +0,0 @@ - + */ + 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); + } } diff --git a/src/Prime/FlasherInterface.php b/src/Prime/FlasherInterface.php index 658569d9..b4cbb4d2 100644 --- a/src/Prime/FlasherInterface.php +++ b/src/Prime/FlasherInterface.php @@ -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); } diff --git a/src/Prime/Manager/AbstractManager.php b/src/Prime/Manager/AbstractManager.php deleted file mode 100644 index d036e05d..00000000 --- a/src/Prime/Manager/AbstractManager.php +++ /dev/null @@ -1,85 +0,0 @@ - - */ - 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); - } -} diff --git a/src/Prime/Notification/Notification.php b/src/Prime/Notification/Notification.php index 36c8014b..b87e7d03 100644 --- a/src/Prime/Notification/Notification.php +++ b/src/Prime/Notification/Notification.php @@ -12,7 +12,7 @@ class Notification implements NotificationInterface /** * @var string */ - protected $type = self::TYPE_SUCCESS; + protected $type = self::TYPE_INFO; /** * @var array diff --git a/src/Prime/Notification/NotificationBuilder.php b/src/Prime/Notification/NotificationBuilder.php index 6f515e07..a2288480 100644 --- a/src/Prime/Notification/NotificationBuilder.php +++ b/src/Prime/Notification/NotificationBuilder.php @@ -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)); diff --git a/src/Prime/Presenter/PresenterInterface.php b/src/Prime/Presenter/PresenterInterface.php deleted file mode 100644 index 5e3eb4d0..00000000 --- a/src/Prime/Presenter/PresenterInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -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))); } } diff --git a/src/Prime/Renderer/RendererInterface.php b/src/Prime/Renderer/RendererInterface.php new file mode 100644 index 00000000..c53ec1c0 --- /dev/null +++ b/src/Prime/Renderer/RendererInterface.php @@ -0,0 +1,13 @@ +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()); diff --git a/src/Prime/Storage/StorageManagerInterface.php b/src/Prime/Storage/StorageManagerInterface.php index d78a7152..07752c66 100644 --- a/src/Prime/Storage/StorageManagerInterface.php +++ b/src/Prime/Storage/StorageManagerInterface.php @@ -3,11 +3,7 @@ namespace Flasher\Prime\Storage; use Flasher\Prime\Envelope; -use Flasher\Prime\Filter\FilterInterface; -/** - * @mixin FilterInterface - */ interface StorageManagerInterface { /** diff --git a/src/Prime/Tests/Manager/ManagerTest.php b/src/Prime/Tests/Manager/ManagerTest.php index f200a426..c2986cfc 100644 --- a/src/Prime/Tests/Manager/ManagerTest.php +++ b/src/Prime/Tests/Manager/ManagerTest.php @@ -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'); } diff --git a/src/SweetAlert/Laravel/.phpstorm.meta.php b/src/SweetAlert/Laravel/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/SweetAlert/Laravel/.phpstorm.meta.php +++ b/src/SweetAlert/Laravel/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel.php b/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel.php index b2cbc7a4..6c1779bc 100644 --- a/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel.php @@ -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; }); diff --git a/src/SweetAlert/Laravel/Tests/FlasherSweetAlertServiceProviderTest.php b/src/SweetAlert/Laravel/Tests/FlasherSweetAlertServiceProviderTest.php index 1664385a..e8176cff 100644 --- a/src/SweetAlert/Laravel/Tests/FlasherSweetAlertServiceProviderTest.php +++ b/src/SweetAlert/Laravel/Tests/FlasherSweetAlertServiceProviderTest.php @@ -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() diff --git a/src/SweetAlert/Prime/SweetAlertFactory.php b/src/SweetAlert/Prime/SweetAlertFactory.php index b38b2109..531beced 100644 --- a/src/SweetAlert/Prime/SweetAlertFactory.php +++ b/src/SweetAlert/Prime/SweetAlertFactory.php @@ -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'); } /** diff --git a/src/SweetAlert/Symfony/.phpstorm.meta.php b/src/SweetAlert/Symfony/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/SweetAlert/Symfony/.phpstorm.meta.php +++ b/src/SweetAlert/Symfony/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Symfony/.phpstorm.meta.php b/src/Symfony/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Symfony/.phpstorm.meta.php +++ b/src/Symfony/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php index c60b6812..6c6c7226 100644 --- a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php @@ -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; diff --git a/src/Symfony/EventListener/SessionListener.php b/src/Symfony/EventListener/SessionListener.php index 819f46c6..fbfa157d 100644 --- a/src/Symfony/EventListener/SessionListener.php +++ b/src/Symfony/EventListener/SessionListener.php @@ -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; diff --git a/src/Symfony/Twig/FlasherTwigExtension.php b/src/Symfony/Twig/FlasherTwigExtension.php index a7af9906..bba422af 100644 --- a/src/Symfony/Twig/FlasherTwigExtension.php +++ b/src/Symfony/Twig/FlasherTwigExtension.php @@ -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; diff --git a/src/Toastr/Laravel/.phpstorm.meta.php b/src/Toastr/Laravel/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Toastr/Laravel/.phpstorm.meta.php +++ b/src/Toastr/Laravel/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@'])); diff --git a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php b/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php index 3b6e1b5c..24759b17 100644 --- a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php @@ -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; }); diff --git a/src/Toastr/Laravel/Tests/FlasherToastrServiceProviderTest.php b/src/Toastr/Laravel/Tests/FlasherToastrServiceProviderTest.php index 96b5200c..e3c9d4cc 100644 --- a/src/Toastr/Laravel/Tests/FlasherToastrServiceProviderTest.php +++ b/src/Toastr/Laravel/Tests/FlasherToastrServiceProviderTest.php @@ -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() diff --git a/src/Toastr/Prime/ToastrFactory.php b/src/Toastr/Prime/ToastrFactory.php index bad6780a..eb19d2a6 100644 --- a/src/Toastr/Prime/ToastrFactory.php +++ b/src/Toastr/Prime/ToastrFactory.php @@ -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'); } /** diff --git a/src/Toastr/Symfony/.phpstorm.meta.php b/src/Toastr/Symfony/.phpstorm.meta.php index aa712a5c..55dcbfa4 100644 --- a/src/Toastr/Symfony/.phpstorm.meta.php +++ b/src/Toastr/Symfony/.phpstorm.meta.php @@ -1,14 +1,3 @@ '@'])); -override(RendererManager::make(''), map(['' => '@'])); -override(PresenterManager::make(''), map(['' => '@']));