From 45faccced7bf7dfe681db418fe702af9f57807b0 Mon Sep 17 00:00:00 2001 From: Khoubza Younes Date: Sun, 6 Dec 2020 04:03:14 +0100 Subject: [PATCH] fix event dispatcher and call the storage service --- composer.json | 21 +--- src/Laravel/NotifyServiceProvider.php | 2 +- src/Laravel/Resources/config/config.php | 2 +- .../ServiceProvider/Providers/Laravel.php | 72 +++++------ .../ServiceProvider/Providers/Laravel4.php | 4 +- .../ServiceProvider/Providers/Laravel50.php | 2 +- .../Tests/NotifyServiceProviderTest.php | 6 +- src/Laravel/helpers.php | 4 +- .../Laravel/NotifyNotyfServiceProvider.php | 6 +- .../ServiceProvider/Providers/Laravel.php | 26 ++-- .../Tests/NotifyNotyfServiceProviderTest.php | 8 +- src/Notyf/Prime/Producer/NotyfProducer.php | 2 +- .../Symfony/Resources/config/services.yaml | 18 +-- .../Laravel/NotifyPnotifyServiceProvider.php | 6 +- .../ServiceProvider/Providers/Laravel.php | 24 ++-- .../NotifyPnotifyServiceProviderTest.php | 8 +- .../Symfony/Resources/config/services.yaml | 16 +-- .../Event/EnvelopeDispatchedEvent.php | 37 ++++++ src/Prime/EventDispatcher/EventDispatcher.php | 13 +- .../EventDispatcherInterface.php | 2 +- .../EventSubscriberInterface.php | 2 +- .../EventListener/MiddlewareListener.php | 35 ++++++ .../PostFilterListener.php} | 15 +-- .../PostFlushListener.php} | 4 +- .../EventListener/StorageListener.php | 32 +++++ ...bstractFlasher.php => AbstractFactory.php} | 34 +++++- ...erface.php => FlasherFactoryInterface.php} | 2 +- src/Prime/Filter/DefaultFilter.php | 22 ++++ src/Prime/Filter/FilterManager.php | 5 +- src/Prime/Filter/FilterManagerInterface.php | 27 +++++ src/Prime/FlasherInterface.php | 6 +- src/Prime/Manager/AbstractManager.php | 4 +- src/Prime/Manager/ManagerInterface.php | 27 ----- .../{NotifyBus.php => FlasherBus.php} | 16 +-- src/Prime/Middleware/FlasherBusInterface.php | 26 ++++ .../Notification/NotificationBuilder.php | 77 +++++++++++- src/Prime/Presenter/AbstractPresenter.php | 38 +++--- src/Prime/Presenter/Adapter/HtmlPresenter.php | 10 +- src/Prime/Presenter/Adapter/JsonPresenter.php | 2 +- src/Prime/Presenter/PresenterManager.php | 5 +- .../Presenter/PresenterManagerInterface.php | 27 +++++ src/Prime/Renderer/RendererInterface.php | 8 ++ src/Prime/Renderer/RendererManager.php | 5 +- .../Renderer/RendererManagerInterface.php | 27 +++++ src/Prime/Storage/StorageManager.php | 1 - src/Prime/Tests/Config/ConfigTest.php | 4 +- .../Tests/Producer/ProducerManagerTest.php | 2 +- .../Tests/Stubs/Producer/FakeProducer.php | 2 +- .../NotifySweetAlertServiceProvider.php | 6 +- .../ServiceProvider/Providers/Laravel.php | 26 ++-- .../NotifySweetAlertServiceProviderTest.php | 8 +- .../Prime/Producer/SweetAlertProducer.php | 2 +- .../Symfony/Resources/config/services.yaml | 18 +-- .../Compiler/EventSubscriberCompilerPass.php | 28 +++++ .../Compiler/FactoryCompilerPass.php | 28 +++++ .../Compiler/FilterCompilerPass.php | 16 +-- .../Compiler/MiddlewareCompilerPass.php | 28 +++++ .../Compiler/PresenterCompilerPass.php | 16 +-- .../Compiler/ProducerCompilerPass.php | 32 ----- .../Compiler/RendererCompilerPass.php | 16 +-- .../DependencyInjection/Configuration.php | 10 +- ...tifyExtension.php => FlasherExtension.php} | 7 +- .../{NotifyBundle.php => FlasherBundle.php} | 10 +- src/Symfony/Resources/config/aliases.yaml | 27 +++++ src/Symfony/Resources/config/config.yaml | 35 ++++++ .../Resources/config/event_subscribers.yaml | 29 +++++ src/Symfony/Resources/config/filters.yaml | 14 +++ src/Symfony/Resources/config/middlewares.yaml | 23 ++++ src/Symfony/Resources/config/presenters.yaml | 26 ++++ src/Symfony/Resources/config/services.yaml | 92 ++------------ src/Symfony/Resources/config/storage.yaml | 11 ++ src/Symfony/Resources/config/twig.yaml | 7 ++ src/Symfony/Resources/public/js/flasher.js | 114 ++++++++++++++++++ src/Symfony/Storage/Storage.php | 98 ++++++++------- ...Extension.php => FlasherTwigExtension.php} | 7 +- .../Laravel/NotifyToastrServiceProvider.php | 6 +- .../ServiceProvider/Providers/Laravel.php | 26 ++-- .../tests/NotifyToastrServiceProviderTest.php | 8 +- src/Toastr/Prime/Producer/ToastrProducer.php | 14 --- src/Toastr/Prime/Toastr.php | 29 +++++ src/Toastr/Prime/ToastrBuilder.php | 24 ++++ src/Toastr/Prime/ToastrFactory.php | 32 +++++ .../Prime/{Renderer => }/ToastrRenderer.php | 26 ++-- .../DependencyInjection/Configuration.php | 4 +- ...tension.php => FlasherToastrExtension.php} | 6 +- ...astrBundle.php => FlasherToastrBundle.php} | 2 +- .../Symfony/Resources/config/services.yaml | 20 +-- src/Toastr/Symfony/composer.json | 2 +- 88 files changed, 1146 insertions(+), 531 deletions(-) create mode 100644 src/Prime/EventDispatcher/Event/EnvelopeDispatchedEvent.php rename src/Prime/EventDispatcher/{EventSubscriber => EventListener}/EventSubscriberInterface.php (71%) create mode 100644 src/Prime/EventDispatcher/EventListener/MiddlewareListener.php rename src/Prime/EventDispatcher/{EventSubscriber/FilterEnvelopesByHopsListener.php => EventListener/PostFilterListener.php} (55%) rename src/Prime/EventDispatcher/{EventSubscriber/RemoveRenderedEnvelopesSubscriber.php => EventListener/PostFlushListener.php} (88%) create mode 100644 src/Prime/EventDispatcher/EventListener/StorageListener.php rename src/Prime/Factory/{AbstractFlasher.php => AbstractFactory.php} (70%) rename src/Prime/Factory/{FactoryInterface.php => FlasherFactoryInterface.php} (94%) create mode 100644 src/Prime/Filter/FilterManagerInterface.php delete mode 100644 src/Prime/Manager/ManagerInterface.php rename src/Prime/Middleware/{NotifyBus.php => FlasherBus.php} (73%) create mode 100644 src/Prime/Middleware/FlasherBusInterface.php create mode 100644 src/Prime/Presenter/PresenterManagerInterface.php create mode 100644 src/Prime/Renderer/RendererManagerInterface.php create mode 100644 src/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPass.php create mode 100644 src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php create mode 100644 src/Symfony/DependencyInjection/Compiler/MiddlewareCompilerPass.php delete mode 100644 src/Symfony/DependencyInjection/Compiler/ProducerCompilerPass.php rename src/Symfony/DependencyInjection/{NotifyExtension.php => FlasherExtension.php} (78%) rename src/Symfony/{NotifyBundle.php => FlasherBundle.php} (53%) create mode 100644 src/Symfony/Resources/config/aliases.yaml create mode 100644 src/Symfony/Resources/config/config.yaml create mode 100644 src/Symfony/Resources/config/event_subscribers.yaml create mode 100644 src/Symfony/Resources/config/filters.yaml create mode 100644 src/Symfony/Resources/config/middlewares.yaml create mode 100644 src/Symfony/Resources/config/presenters.yaml create mode 100644 src/Symfony/Resources/config/storage.yaml create mode 100644 src/Symfony/Resources/config/twig.yaml create mode 100644 src/Symfony/Resources/public/js/flasher.js rename src/Symfony/Twig/{NotifyTwigExtension.php => FlasherTwigExtension.php} (71%) delete mode 100644 src/Toastr/Prime/Producer/ToastrProducer.php create mode 100644 src/Toastr/Prime/Toastr.php create mode 100644 src/Toastr/Prime/ToastrBuilder.php create mode 100644 src/Toastr/Prime/ToastrFactory.php rename src/Toastr/Prime/{Renderer => }/ToastrRenderer.php (65%) rename src/Toastr/Symfony/DependencyInjection/{NotifyToastrExtension.php => FlasherToastrExtension.php} (85%) rename src/Toastr/Symfony/{NotifyToastrBundle.php => FlasherToastrBundle.php} (69%) diff --git a/composer.json b/composer.json index 3c52fc8a..aa57523e 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "description": "All flasher components in one place for easy maintenance with splitsh", - "name": "php-flasher/flasher", + "name": "php-flasher/php-flasher", "type": "project", "license": "MIT", "authors": [ @@ -13,24 +13,7 @@ ], "require": { "php": ">=5.3", - "ext-json": "*", - "illuminate/support": ">=4.0", - "symfony/config": ">=2.1", - "symfony/dependency-injection": ">=2.1", - "symfony/http-kernel": ">=2.1", - "symfony/yaml": ">=2.1" - }, - "replace": { - "php-flasher/flasher": "self.version", - "php-flasher/flasher-laravel": "self.version", - "php-flasher/flasher-symfony": "self.version", - "php-flasher/flasher-toastr": "self.version", - "php-flasher/flasher-laravel-toastr": "self.version", - "php-flasher/flasher-symfony-toastr": "self.version" - }, - "require-dev": { - "phpunit/phpunit": ">=4.8.36", - "orchestra/testbench": ">=2.0" + "ext-json": "*" }, "autoload": { "psr-4": { diff --git a/src/Laravel/NotifyServiceProvider.php b/src/Laravel/NotifyServiceProvider.php index c929acb3..df899f58 100644 --- a/src/Laravel/NotifyServiceProvider.php +++ b/src/Laravel/NotifyServiceProvider.php @@ -33,7 +33,7 @@ final class NotifyServiceProvider extends ServiceProvider public function provides() { return array( - 'notify.producer', + 'flasher.factory', ); } diff --git a/src/Laravel/Resources/config/config.php b/src/Laravel/Resources/config/config.php index 9e46f6d2..3b6fa8af 100644 --- a/src/Laravel/Resources/config/config.php +++ b/src/Laravel/Resources/config/config.php @@ -4,7 +4,7 @@ return array( 'default' => 'toastr', 'scripts' => array( - '/vendor/php-flasher/flasher/assets/js/notify.js' + '/vendor/php-flasher/flasher/assets/js/flasher.js' ), 'styles' => array( diff --git a/src/Laravel/ServiceProvider/Providers/Laravel.php b/src/Laravel/ServiceProvider/Providers/Laravel.php index 61049ef7..b5a1b172 100644 --- a/src/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Laravel/ServiceProvider/Providers/Laravel.php @@ -36,7 +36,7 @@ class Laravel implements ServiceProviderInterface { $source = realpath($raw = __DIR__.'/../../../resources/config/config.php') ?: $raw; - $provider->publishes(array($source => config_path('notify.php')), 'config'); + $provider->publishes(array($source => config_path('flasher.php')), 'config'); $provider->mergeConfigFrom($source, 'notify'); } @@ -48,7 +48,7 @@ class Laravel implements ServiceProviderInterface public function registerNotifyServices() { - $this->app->singleton('notify.config', function (Application $app) { + $this->app->singleton('flasher.config', function (Application $app) { return new Config($app['config'], '.'); }); @@ -57,80 +57,80 @@ class Laravel implements ServiceProviderInterface public function registerCommonServices() { - $this->app->singleton('notify.producer', function (Application $app) { - return new Flasher($app['notify.config']); + $this->app->singleton('flasher.factory', function (Application $app) { + return new Flasher($app['flasher.config']); }); - $this->app->singleton('notify.storage', function (Application $app) { + $this->app->singleton('flasher.storage', function (Application $app) { return new Storage($app['session']); }); - $this->app->singleton('notify.filter', function (Application $app) { - return new FilterManager($app['notify.config']); + $this->app->singleton('flasher.filter', function (Application $app) { + return new FilterManager($app['flasher.config']); }); - $this->app->singleton('notify.renderer', function (Application $app) { - return new RendererManager($app['notify.config']); + $this->app->singleton('flasher.renderer', function (Application $app) { + return new RendererManager($app['flasher.config']); }); - $this->app->singleton('notify.presenter', function (Application $app) { + $this->app->singleton('flasher.presenter', function (Application $app) { return new PresenterManager(); }); - $this->app->singleton('notify.presenter.html', function (Application $app) { - return new HtmlPresenter($app['notify.config'], $app['notify.storage'], $app['notify.filter'], $app['notify.renderer']); + $this->app->singleton('flasher.presenter.html', function (Application $app) { + return new HtmlPresenter($app['flasher.config'], $app['flasher.storage'], $app['flasher.filter'], $app['flasher.renderer']); }); - $this->app->singleton('notify.presenter.json', function (Application $app) { - return new JsonPresenter($app['notify.config'], $app['notify.storage'], $app['notify.filter'], $app['notify.renderer']); + $this->app->singleton('flasher.presenter.json', function (Application $app) { + return new JsonPresenter($app['flasher.config'], $app['flasher.storage'], $app['flasher.filter'], $app['flasher.renderer']); }); - $this->app->singleton('notify.filter_builder', function (Application $app) { + $this->app->singleton('flasher.filter_builder', function (Application $app) { return new FilterBuilder(); }); - $this->app->singleton('notify.filter.default', function (Application $app) { - return new DefaultFilter($app['notify.filter_builder']); + $this->app->singleton('flasher.filter.default', function (Application $app) { + return new DefaultFilter($app['flasher.filter_builder']); }); - $this->app->singleton('notify.middleware', function (Application $app) { - return new MiddlewareManager($app['notify.config']); + $this->app->singleton('flasher.middleware', function (Application $app) { + return new MiddlewareManager($app['flasher.config']); }); - $this->app->extend('notify.presenter', function (PresenterManager $manager, Container $app) { - $manager->addDriver('html', $app['notify.presenter.html']); + $this->app->extend('flasher.presenter', function (PresenterManager $manager, Container $app) { + $manager->addDriver('html', $app['flasher.presenter.html']); return $manager; }); - $this->app->extend('notify.presenter', function (PresenterManager $manager, Container $app) { - $manager->addDriver('json', $app['notify.presenter.json']); + $this->app->extend('flasher.presenter', function (PresenterManager $manager, Container $app) { + $manager->addDriver('json', $app['flasher.presenter.json']); return $manager; }); - $this->app->extend('notify.filter', function (FilterManager $manager, Container $app) { - $manager->addDriver('default', $app['notify.filter.default']); + $this->app->extend('flasher.filter', function (FilterManager $manager, Container $app) { + $manager->addDriver('default', $app['flasher.filter.default']); return $manager; }); - $this->app->alias('notify.config', 'Flasher\Laravel\Config\Config'); - $this->app->alias('notify.producer', 'Flasher\Prime\Flasher'); - $this->app->alias('notify.presenter', 'Flasher\Prime\Presenter\PresenterManager'); - $this->app->alias('notify.middleware', 'Flasher\Prime\Middleware\MiddlewareManager'); - $this->app->alias('notify.storage', 'Flasher\Laravel\Storage\Storage'); - $this->app->alias('notify.filter', 'Flasher\Prime\Filter\FilterManager'); - $this->app->alias('notify.presenter.html', 'Flasher\Prime\Presenter\Adapter\HtmlPresenter'); - $this->app->alias('notify.presenter.json', 'Flasher\Prime\Presenter\Adapter\JsonPresenter'); - $this->app->alias('notify.filter_builder', 'Flasher\Prime\Filter\FilterBuilder'); - $this->app->alias('notify.filter.default', 'Flasher\Prime\Filter\DefaultFilter'); + $this->app->alias('flasher.config', 'Flasher\Laravel\Config\Config'); + $this->app->alias('flasher.factory', 'Flasher\Prime\Flasher'); + $this->app->alias('flasher.presenter', 'Flasher\Prime\Presenter\PresenterManager'); + $this->app->alias('flasher.middleware', 'Flasher\Prime\Middleware\MiddlewareManager'); + $this->app->alias('flasher.storage', 'Flasher\Laravel\Storage\Storage'); + $this->app->alias('flasher.filter', 'Flasher\Prime\Filter\FilterManager'); + $this->app->alias('flasher.presenter.html', 'Flasher\Prime\Presenter\Adapter\HtmlPresenter'); + $this->app->alias('flasher.presenter.json', 'Flasher\Prime\Presenter\Adapter\JsonPresenter'); + $this->app->alias('flasher.filter_builder', 'Flasher\Prime\Filter\FilterBuilder'); + $this->app->alias('flasher.filter.default', 'Flasher\Prime\Filter\DefaultFilter'); } public function registerBladeDirectives() { Blade::directive('notify_render', function ($criteria = null) { - return "render($criteria); ?>"; + return "render($criteria); ?>"; }); } } diff --git a/src/Laravel/ServiceProvider/Providers/Laravel4.php b/src/Laravel/ServiceProvider/Providers/Laravel4.php index 378e42d8..1adab6a1 100644 --- a/src/Laravel/ServiceProvider/Providers/Laravel4.php +++ b/src/Laravel/ServiceProvider/Providers/Laravel4.php @@ -26,7 +26,7 @@ final class Laravel4 extends Laravel public function registerNotifyServices() { - $this->app->singleton('notify.config', function (Application $app) { + $this->app->singleton('flasher.config', function (Application $app) { return new Config($app['config'], '::'); }); @@ -38,7 +38,7 @@ final class Laravel4 extends Laravel Blade::extend(function ($view, $compiler) { $pattern = $compiler->createPlainMatcher('notify_render(.*)'); - return preg_replace($pattern, '$1render($2); ?>', $view); + return preg_replace($pattern, '$1render($2); ?>', $view); }); } } diff --git a/src/Laravel/ServiceProvider/Providers/Laravel50.php b/src/Laravel/ServiceProvider/Providers/Laravel50.php index 3f0b8702..d129a0ae 100644 --- a/src/Laravel/ServiceProvider/Providers/Laravel50.php +++ b/src/Laravel/ServiceProvider/Providers/Laravel50.php @@ -17,7 +17,7 @@ final class Laravel50 extends Laravel Blade::extend(function ($view, $compiler) { $pattern = $compiler->createPlainMatcher('notify_render(.*)'); - return preg_replace($pattern, '$1render($2); ?>', $view); + return preg_replace($pattern, '$1render($2); ?>', $view); }); } } diff --git a/src/Laravel/Tests/NotifyServiceProviderTest.php b/src/Laravel/Tests/NotifyServiceProviderTest.php index 14b431a5..2e551678 100644 --- a/src/Laravel/Tests/NotifyServiceProviderTest.php +++ b/src/Laravel/Tests/NotifyServiceProviderTest.php @@ -8,12 +8,12 @@ class NotifyServiceProviderTest extends TestCase { public function test_notify_service_exists() { - $this->assertTrue($this->app->bound('notify.producer')); + $this->assertTrue($this->app->bound('flasher.factory')); } public function test_notify_manager_get_config() { - $notify = $this->app->make('notify.producer'); + $notify = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass(get_class($notify)); $config = $reflection->getProperty('config'); @@ -27,6 +27,6 @@ class NotifyServiceProviderTest extends TestCase /** @var BladeCompiler $blade */ $blade = $this->app->make('view')->getEngineResolver()->resolve('blade')->getCompiler(); - $this->assertEquals("render(); ?>", $blade->compileString('@notify_render')); + $this->assertEquals("render(); ?>", $blade->compileString('@notify_render')); } } diff --git a/src/Laravel/helpers.php b/src/Laravel/helpers.php index b86eccc9..683e4a49 100644 --- a/src/Laravel/helpers.php +++ b/src/Laravel/helpers.php @@ -13,9 +13,9 @@ if (!function_exists('notify')) { function notify($message = null, $type = 'success', $title = '', array $options = array(), array $stamps = array()) { if (is_null($message) && 0 === func_num_args()) { - return app('notify.producer'); + return app('flasher.factory'); } - return app('notify.producer')->render($type, $message, $title, $options, $stamps); + return app('flasher.factory')->render($type, $message, $title, $options, $stamps); } } diff --git a/src/Notyf/Laravel/NotifyNotyfServiceProvider.php b/src/Notyf/Laravel/NotifyNotyfServiceProvider.php index f3817a32..cc7e7b48 100644 --- a/src/Notyf/Laravel/NotifyNotyfServiceProvider.php +++ b/src/Notyf/Laravel/NotifyNotyfServiceProvider.php @@ -31,9 +31,9 @@ class NotifyNotyfServiceProvider extends ServiceProvider public function provides() { return array( - 'notify.producer', - 'notify.producer.notyf', - 'notify.renderer.notyf', + 'flasher.factory', + 'flasher.factory.notyf', + 'flasher.renderer.notyf', ); } diff --git a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php b/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php index acacc9ec..a44f0c5d 100644 --- a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php @@ -3,7 +3,7 @@ namespace Flasher\Notyf\Laravel\ServiceProvider\Providers; use Flasher\Notyf\LaravelFlasher\PrimeNotyfServiceProvider; -use Flasher\Notyf\Prime\Producer\NotyfProducer; +use Flasher\Notyf\Prime\Factory\NotyfProducer; use Flasher\Notyf\Prime\Renderer\NotyfRenderer; use Flasher\Prime\Flasher; use Flasher\Prime\Renderer\RendererManager; @@ -35,25 +35,25 @@ class Laravel implements ServiceProviderInterface public function registerNotifyNotyfServices() { - $this->app->singleton('notify.producer.notyf', function (Container $app) { - return new NotyfProducer($app['notify.storage'], $app['notify.middleware']); + $this->app->singleton('flasher.factory.notyf', function (Container $app) { + return new NotyfProducer($app['flasher.storage'], $app['flasher.middleware']); }); - $this->app->singleton('notify.renderer.notyf', function (Container $app) { - return new NotyfRenderer($app['notify.config']); + $this->app->singleton('flasher.renderer.notyf', function (Container $app) { + return new NotyfRenderer($app['flasher.config']); }); - $this->app->alias('notify.producer.notyf', 'Flasher\Notyf\Prime\Producer\NotyfProducer'); - $this->app->alias('notify.renderer.notyf', 'Flasher\Notyf\Prime\Renderer\NotyfRenderer'); + $this->app->alias('flasher.factory.notyf', 'Flasher\Notyf\Prime\Factory\NotyfProducer'); + $this->app->alias('flasher.renderer.notyf', 'Flasher\Notyf\Prime\Renderer\NotyfRenderer'); - $this->app->extend('notify.producer', function (Flasher $manager, Container $app) { - $manager->addDriver('notyf', $app['notify.producer.notyf']); + $this->app->extend('flasher.factory', function (Flasher $manager, Container $app) { + $manager->addDriver('notyf', $app['flasher.factory.notyf']); return $manager; }); - $this->app->extend('notify.renderer', function (RendererManager $manager, Container $app) { - $manager->addDriver('notyf', $app['notify.renderer.notyf']); + $this->app->extend('flasher.renderer', function (RendererManager $manager, Container $app) { + $manager->addDriver('notyf', $app['flasher.renderer.notyf']); return $manager; }); @@ -61,10 +61,10 @@ class Laravel implements ServiceProviderInterface public function mergeConfigFromNotyf() { - $notifyConfig = $this->app['config']->get('notify.adapters.notyf', array()); + $notifyConfig = $this->app['config']->get('flasher.adapters.notyf', array()); $notyfConfig = $this->app['config']->get('notify_notyf', array()); - $this->app['config']->set('notify.adapters.notyf', array_merge($notyfConfig, $notifyConfig)); + $this->app['config']->set('flasher.adapters.notyf', array_merge($notyfConfig, $notifyConfig)); } } diff --git a/src/Notyf/Laravel/Tests/NotifyNotyfServiceProviderTest.php b/src/Notyf/Laravel/Tests/NotifyNotyfServiceProviderTest.php index 4cf5590f..cf7ed557 100644 --- a/src/Notyf/Laravel/Tests/NotifyNotyfServiceProviderTest.php +++ b/src/Notyf/Laravel/Tests/NotifyNotyfServiceProviderTest.php @@ -6,13 +6,13 @@ class NotifyNotyfServiceProviderTest extends TestCase { public function testContainerContainNotifyServices() { - $this->assertTrue($this->app->bound('notify.producer')); - $this->assertTrue($this->app->bound('notify.producer.notyf')); + $this->assertTrue($this->app->bound('flasher.factory')); + $this->assertTrue($this->app->bound('flasher.factory.notyf')); } public function testNotifyFactoryIsAddedToExtensionsArray() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('drivers'); @@ -26,7 +26,7 @@ class NotifyNotyfServiceProviderTest extends TestCase public function testConfigNotyfInjectedInGlobalNotifyConfig() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('config'); diff --git a/src/Notyf/Prime/Producer/NotyfProducer.php b/src/Notyf/Prime/Producer/NotyfProducer.php index 35085edc..934488a4 100644 --- a/src/Notyf/Prime/Producer/NotyfProducer.php +++ b/src/Notyf/Prime/Producer/NotyfProducer.php @@ -1,6 +1,6 @@ app->singleton('notify.producer.pnotify', function (Container $app) { - return new PnotifyProducer($app['notify.storage'], $app['notify.middleware']); + $this->app->singleton('flasher.factory.pnotify', function (Container $app) { + return new PnotifyProducer($app['flasher.storage'], $app['flasher.middleware']); }); - $this->app->singleton('notify.renderer.pnotify', function (Container $app) { - return new PnotifyRenderer($app['notify.config']); + $this->app->singleton('flasher.renderer.pnotify', function (Container $app) { + return new PnotifyRenderer($app['flasher.config']); }); - $this->app->alias('notify.producer.pnotify', 'Flasher\PFlasher\Prime\TestsProducer\PnotifyProducer'); - $this->app->alias('notify.renderer.pnotify', 'Flasher\PFlasher\Prime\Renderer\PnotifyRenderer'); + $this->app->alias('flasher.factory.pnotify', 'Flasher\PFlasher\Prime\TestsProducer\PnotifyProducer'); + $this->app->alias('flasher.renderer.pnotify', 'Flasher\PFlasher\Prime\Renderer\PnotifyRenderer'); - $this->app->extend('notify.producer', function (Flasher $manager, Container $app) { - $manager->addDriver('pnotify', $app['notify.producer.pnotify']); + $this->app->extend('flasher.factory', function (Flasher $manager, Container $app) { + $manager->addDriver('pnotify', $app['flasher.factory.pnotify']); return $manager; }); - $this->app->extend('notify.renderer', function (RendererManager $manager, Container $app) { - $manager->addDriver('pnotify', $app['notify.renderer.pnotify']); + $this->app->extend('flasher.renderer', function (RendererManager $manager, Container $app) { + $manager->addDriver('pnotify', $app['flasher.renderer.pnotify']); return $manager; }); @@ -61,10 +61,10 @@ class Laravel implements ServiceProviderInterface public function mergeConfigFromPnotify() { - $notifyConfig = $this->app['config']->get('notify.adapters.pnotify', array()); + $notifyConfig = $this->app['config']->get('flasher.adapters.pnotify', array()); $pnotifyConfig = $this->app['config']->get('notify_pnotify', array()); - $this->app['config']->set('notify.adapters.pnotify', array_merge($pnotifyConfig, $notifyConfig)); + $this->app['config']->set('flasher.adapters.pnotify', array_merge($pnotifyConfig, $notifyConfig)); } } diff --git a/src/Pnotify/Laravel/Tests/NotifyPnotifyServiceProviderTest.php b/src/Pnotify/Laravel/Tests/NotifyPnotifyServiceProviderTest.php index 05c2bfa3..46e987e1 100644 --- a/src/Pnotify/Laravel/Tests/NotifyPnotifyServiceProviderTest.php +++ b/src/Pnotify/Laravel/Tests/NotifyPnotifyServiceProviderTest.php @@ -6,13 +6,13 @@ class NotifyPnotifyServiceProviderTest extends TestCase { public function testContainerContainNotifyServices() { - $this->assertTrue($this->app->bound('notify.producer')); - $this->assertTrue($this->app->bound('notify.producer.pnotify')); + $this->assertTrue($this->app->bound('flasher.factory')); + $this->assertTrue($this->app->bound('flasher.factory.pnotify')); } public function testNotifyFactoryIsAddedToExtensionsArray() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('drivers'); @@ -26,7 +26,7 @@ class NotifyPnotifyServiceProviderTest extends TestCase public function testConfigPnotifyInjectedInGlobalNotifyConfig() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('config'); diff --git a/src/Pnotify/Symfony/Resources/config/services.yaml b/src/Pnotify/Symfony/Resources/config/services.yaml index 1aa68016..0fa5a2b2 100644 --- a/src/Pnotify/Symfony/Resources/config/services.yaml +++ b/src/Pnotify/Symfony/Resources/config/services.yaml @@ -1,16 +1,16 @@ services: - notify.producer.pnotify: - parent: 'notify.producer.abstract' + flasher.factory.pnotify: + parent: 'flasher.factory.abstract' class: Flasher\PFlasher\Prime\TestsProducer\PnotifyProducer tags: - - { name: 'notify.producer', alias: 'pnotify' } + - { name: 'flasher.factory', alias: 'pnotify' } - notify.renderer.pnotify: + flasher.renderer.pnotify: class: Flasher\PFlasher\Prime\Renderer\PnotifyRenderer arguments: - - '@notify.config' + - '@flasher.config' tags: - - { name: 'notify.renderer', alias: 'pnotify' } + - { name: 'flasher.renderer', alias: 'pnotify' } - Flasher\PFlasher\Prime\TestsProducer\PnotifyProducer: '@notify.producer.pnotify' - Flasher\PFlasher\Prime\Renderer\PnotifyRenderer: '@notify.renderer.pnotify' + Flasher\PFlasher\Prime\TestsProducer\PnotifyProducer: '@flasher.factory.pnotify' + Flasher\PFlasher\Prime\Renderer\PnotifyRenderer: '@flasher.renderer.pnotify' diff --git a/src/Prime/EventDispatcher/Event/EnvelopeDispatchedEvent.php b/src/Prime/EventDispatcher/Event/EnvelopeDispatchedEvent.php new file mode 100644 index 00000000..6ec59de6 --- /dev/null +++ b/src/Prime/EventDispatcher/Event/EnvelopeDispatchedEvent.php @@ -0,0 +1,37 @@ +envelope = $envelope; + } + + /** + * @return Envelope + */ + public function getEnvelope() + { + return $this->envelope; + } + + /** + * @param Envelope $envelope + */ + public function setEnvelope(Envelope $envelope) + { + $this->envelope = $envelope; + } +} diff --git a/src/Prime/EventDispatcher/EventDispatcher.php b/src/Prime/EventDispatcher/EventDispatcher.php index 874de6b6..a6d953f0 100644 --- a/src/Prime/EventDispatcher/EventDispatcher.php +++ b/src/Prime/EventDispatcher/EventDispatcher.php @@ -3,7 +3,7 @@ namespace Flasher\Prime\EventDispatcher; use Flasher\Prime\EventDispatcher\Event\StoppableEventInterface; -use Flasher\Prime\EventDispatcher\EventSubscriber\EventSubscriberInterface; +use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface; final class EventDispatcher implements EventDispatcherInterface { @@ -81,10 +81,15 @@ final class EventDispatcher implements EventDispatcherInterface */ public function addSubscriber(EventSubscriberInterface $subscriber) { - foreach ((array) $subscriber->getSubscribedEvents() as $eventName => $params) { - if (\is_string($params)) { + foreach ((array) $subscriber->getSubscribedEvents() as $eventName => $params) { + if (is_int($eventName)) { + $eventName = $params; + $params = '__invoke'; + } + + if (is_string($params)) { $this->addListener($eventName, array($subscriber, $params)); - } elseif (\is_string($params[0])) { + } elseif (is_string($params[0])) { $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0); } else { foreach ($params as $listener) { diff --git a/src/Prime/EventDispatcher/EventDispatcherInterface.php b/src/Prime/EventDispatcher/EventDispatcherInterface.php index a4c5c4e9..9bb56387 100644 --- a/src/Prime/EventDispatcher/EventDispatcherInterface.php +++ b/src/Prime/EventDispatcher/EventDispatcherInterface.php @@ -2,7 +2,7 @@ namespace Flasher\Prime\EventDispatcher; -use Flasher\Prime\EventDispatcher\EventSubscriber\EventSubscriberInterface; +use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface; interface EventDispatcherInterface { diff --git a/src/Prime/EventDispatcher/EventSubscriber/EventSubscriberInterface.php b/src/Prime/EventDispatcher/EventListener/EventSubscriberInterface.php similarity index 71% rename from src/Prime/EventDispatcher/EventSubscriber/EventSubscriberInterface.php rename to src/Prime/EventDispatcher/EventListener/EventSubscriberInterface.php index 1c136437..7780faaa 100644 --- a/src/Prime/EventDispatcher/EventSubscriber/EventSubscriberInterface.php +++ b/src/Prime/EventDispatcher/EventListener/EventSubscriberInterface.php @@ -1,6 +1,6 @@ flasherBus = $flasherBus; + } + + /** + * @param EnvelopeDispatchedEvent $event + */ + public function __invoke(EnvelopeDispatchedEvent $event) + { + $this->flasherBus->dispatch($event->getEnvelope()); + } + + public static function getSubscribedEvents() + { + return 'Flasher\Prime\EventDispatcher\Event\EnvelopeDispatchedEvent'; + } +} diff --git a/src/Prime/EventDispatcher/EventSubscriber/FilterEnvelopesByHopsListener.php b/src/Prime/EventDispatcher/EventListener/PostFilterListener.php similarity index 55% rename from src/Prime/EventDispatcher/EventSubscriber/FilterEnvelopesByHopsListener.php rename to src/Prime/EventDispatcher/EventListener/PostFilterListener.php index 23c99a01..d91853ab 100644 --- a/src/Prime/EventDispatcher/EventSubscriber/FilterEnvelopesByHopsListener.php +++ b/src/Prime/EventDispatcher/EventListener/PostFilterListener.php @@ -1,11 +1,11 @@ getEnvelopes(); - $envelopes = array_filter( - $envelopes, - static function (Envelope $envelope) { - $hopsStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp'); + $envelopes = array_filter($envelopes, static function (Envelope $envelope) { + $hopsStamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp'); - return $hopsStamp->getAmount() > 0; - } - ); + return $hopsStamp->getAmount() > 0; + }); $event->setEnvelopes($envelopes); } diff --git a/src/Prime/EventDispatcher/EventSubscriber/RemoveRenderedEnvelopesSubscriber.php b/src/Prime/EventDispatcher/EventListener/PostFlushListener.php similarity index 88% rename from src/Prime/EventDispatcher/EventSubscriber/RemoveRenderedEnvelopesSubscriber.php rename to src/Prime/EventDispatcher/EventListener/PostFlushListener.php index e5ea6a0a..aa6864ec 100644 --- a/src/Prime/EventDispatcher/EventSubscriber/RemoveRenderedEnvelopesSubscriber.php +++ b/src/Prime/EventDispatcher/EventListener/PostFlushListener.php @@ -1,12 +1,12 @@ storage = $storage; + } + + public function __invoke(EnvelopeDispatchedEvent $event) + { + $this->storage->add($event->getEnvelope()); + } + + public static function getSubscribedEvents() + { + return 'Flasher\Prime\EventDispatcher\Event\EnvelopeDispatchedEvent'; + } +} diff --git a/src/Prime/Factory/AbstractFlasher.php b/src/Prime/Factory/AbstractFactory.php similarity index 70% rename from src/Prime/Factory/AbstractFlasher.php rename to src/Prime/Factory/AbstractFactory.php index 7ddc4fc1..b8bf4d9f 100644 --- a/src/Prime/Factory/AbstractFlasher.php +++ b/src/Prime/Factory/AbstractFactory.php @@ -2,6 +2,7 @@ namespace Flasher\Prime\Factory; +use Flasher\Prime\EventDispatcher\EventDispatcherInterface; use Flasher\Prime\Notification\Notification; use Flasher\Prime\Notification\NotificationBuilder; use Flasher\Prime\Notification\NotificationBuilderInterface; @@ -22,14 +23,27 @@ use Flasher\Prime\Notification\NotificationInterface; * @method NotificationBuilderInterface warning($message = null, array $options = array()) * @method NotificationInterface getNotification() */ -abstract class AbstractFlasher implements FactoryInterface +abstract class AbstractFactory implements FlasherFactoryInterface { + /** + * @var EventDispatcherInterface + */ + protected $eventDispatcher; + + /** + * @param EventDispatcherInterface $eventDispatcher + */ + public function __construct(EventDispatcherInterface $eventDispatcher) + { + $this->eventDispatcher = $eventDispatcher; + } + /** * {@inheritdoc} */ public function createNotificationBuilder() { - return new NotificationBuilder($this->createNotification()); + return new NotificationBuilder($this->getEventDispatcher(), $this->createNotification(), $this->createHandler()); } /** @@ -40,6 +54,14 @@ abstract class AbstractFlasher implements FactoryInterface return new Notification(); } + /** + * {@inheritdoc} + */ + public function createHandler() + { + return null; + } + /** * @inheritDoc */ @@ -60,4 +82,12 @@ abstract class AbstractFlasher implements FactoryInterface { return call_user_func_array(array($this->createNotificationBuilder(), $method), $parameters); } + + /** + * @return EventDispatcherInterface + */ + public function getEventDispatcher() + { + return $this->eventDispatcher; + } } diff --git a/src/Prime/Factory/FactoryInterface.php b/src/Prime/Factory/FlasherFactoryInterface.php similarity index 94% rename from src/Prime/Factory/FactoryInterface.php rename to src/Prime/Factory/FlasherFactoryInterface.php index 3d9663e0..dbd68b17 100644 --- a/src/Prime/Factory/FactoryInterface.php +++ b/src/Prime/Factory/FlasherFactoryInterface.php @@ -5,7 +5,7 @@ namespace Flasher\Prime\Factory; use Flasher\Prime\Notification\NotificationBuilderInterface; use Flasher\Prime\Notification\NotificationInterface; -interface FactoryInterface +interface FlasherFactoryInterface { /** * @return NotificationBuilderInterface diff --git a/src/Prime/Filter/DefaultFilter.php b/src/Prime/Filter/DefaultFilter.php index 2f8a49c9..281e7364 100644 --- a/src/Prime/Filter/DefaultFilter.php +++ b/src/Prime/Filter/DefaultFilter.php @@ -2,17 +2,39 @@ 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); } + + /** + * @inheritDoc + */ + public function supports($name = null, array $context = array()) + { + return in_array($name, array(__CLASS__, 'default')); + } } diff --git a/src/Prime/Filter/FilterManager.php b/src/Prime/Filter/FilterManager.php index 856763cb..0d1b8078 100644 --- a/src/Prime/Filter/FilterManager.php +++ b/src/Prime/Filter/FilterManager.php @@ -4,10 +4,7 @@ namespace Flasher\Prime\Filter; use Flasher\Prime\Manager\AbstractManager; -/** - * @method \Flasher\Prime\Filter\FilterInterface make($driver = null) - */ -final class FilterManager extends AbstractManager +final class FilterManager extends AbstractManager implements FilterManagerInterface { protected function getDefaultDriver() { diff --git a/src/Prime/Filter/FilterManagerInterface.php b/src/Prime/Filter/FilterManagerInterface.php new file mode 100644 index 00000000..592f3952 --- /dev/null +++ b/src/Prime/Filter/FilterManagerInterface.php @@ -0,0 +1,27 @@ +getDefaultDriver(); - if (is_array($name)) { - $context = $name; + if (!is_string($name)) { + $context = is_array($name) ? $name : array($name); $name = null; } diff --git a/src/Prime/Manager/ManagerInterface.php b/src/Prime/Manager/ManagerInterface.php deleted file mode 100644 index 4fdcd898..00000000 --- a/src/Prime/Manager/ManagerInterface.php +++ /dev/null @@ -1,27 +0,0 @@ -eventDispatcher = $eventDispatcher; + + $notification = $notification ?: new Notification(); $this->envelope = Envelope::wrap($notification); + + $handler = $handler ?: get_class($notification); + $this->handler($handler); } /** @@ -123,6 +140,16 @@ class NotificationBuilder implements NotificationBuilderInterface return $this->type(NotificationInterface::TYPE_WARNING, $message, $options); } + /** + * @inheritDoc + */ + public function handler($handler) + { + $this->envelope->withStamp(new HandlerStamp($handler)); + + return $this; + } + /** * @inheritDoc */ @@ -149,10 +176,50 @@ 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)); return $this; } + + /** + * @inheritDoc + */ + public function with($stamps = array()) + { + $this->envelope->with($stamps); + + return $this; + } + + /** + * @inheritDoc + */ + public function withStamp($stamps = array()) + { + $this->envelope->withStamp($stamps); + + return $this; + } + + /** + * Dispatch the notification to the flasher bus + * + * @param array $stamps + * + * @return Envelope|mixed + */ + public function dispatch($stamps = array()) + { + if (!empty($stamps)) { + $this->with($stamps); + } + + $envelope = $this->getEnvelope(); + + $event = new EnvelopeDispatchedEvent($envelope); + + return $this->eventDispatcher->dispatch($event); + } } diff --git a/src/Prime/Presenter/AbstractPresenter.php b/src/Prime/Presenter/AbstractPresenter.php index bf37e041..7f368736 100644 --- a/src/Prime/Presenter/AbstractPresenter.php +++ b/src/Prime/Presenter/AbstractPresenter.php @@ -6,12 +6,12 @@ use Flasher\Prime\Config\ConfigInterface; use Flasher\Prime\Envelope; use Flasher\Prime\EventDispatcher\Event\PostFilterEvent; use Flasher\Prime\EventDispatcher\EventDispatcherInterface; -use Flasher\Prime\Filter\FilterManager; +use Flasher\Prime\Filter\FilterManagerInterface; use Flasher\Prime\Renderer\HasOptionsInterface; use Flasher\Prime\Renderer\HasScriptsInterface; use Flasher\Prime\Renderer\HasStylesInterface; -use Flasher\Prime\Renderer\RendererManager; -use Flasher\Prime\Storage\StorageInterface; +use Flasher\Prime\Renderer\RendererManagerInterface; +use Flasher\Prime\Storage\StorageManagerInterface; abstract class AbstractPresenter implements PresenterInterface { @@ -26,17 +26,17 @@ abstract class AbstractPresenter implements PresenterInterface protected $config; /** - * @var StorageInterface + * @var StorageManagerInterface */ - protected $storage; + protected $storageManager; /** - * @var FilterManager + * @var FilterManagerInterface */ protected $filterManager; /** - * @var RendererManager + * @var RendererManagerInterface */ protected $rendererManager; @@ -45,20 +45,20 @@ abstract class AbstractPresenter implements PresenterInterface * * @param EventDispatcherInterface $eventDispatcher * @param ConfigInterface $config - * @param StorageInterface $storage - * @param FilterManager $filterManager - * @param RendererManager $rendererManager + * @param StorageManagerInterface $storageManager + * @param FilterManagerInterface $filterManager + * @param RendererManagerInterface $rendererManager */ public function __construct( EventDispatcherInterface $eventDispatcher, ConfigInterface $config, - StorageInterface $storage, - FilterManager $filterManager, - RendererManager $rendererManager + StorageManagerInterface $storageManager, + FilterManagerInterface $filterManager, + RendererManagerInterface $rendererManager ) { $this->eventDispatcher = $eventDispatcher; $this->config = $config; - $this->storage = $storage; + $this->storageManager = $storageManager; $this->filterManager = $filterManager; $this->rendererManager = $rendererManager; } @@ -81,7 +81,7 @@ abstract class AbstractPresenter implements PresenterInterface { $filter = $this->filterManager->make($filterName); - $envelopes = $this->storage->all(); + $envelopes = $this->storageManager->all(); $event = new PostFilterEvent($envelopes); $this->eventDispatcher->dispatch($event); @@ -133,18 +133,18 @@ abstract class AbstractPresenter implements PresenterInterface $renderers = array(); foreach ($envelopes as $envelope) { - $rendererStamp = $envelope->get('Flasher\Prime\Stamp\HandlerStamp'); - if (in_array($rendererStamp->getHandler(), $renderers)) { + $handlerStamp = $envelope->get('Flasher\Prime\Stamp\HandlerStamp'); + if (in_array($handlerStamp->getHandler(), $renderers)) { continue; } - $renderer = $this->rendererManager->make($rendererStamp->getHandler()); + $renderer = $this->rendererManager->make($handlerStamp->getHandler()); if (!$renderer instanceof HasScriptsInterface) { continue; } $files = array_merge($files, $renderer->getScripts()); - $renderers[] = $rendererStamp->getHandler(); + $renderers[] = $handlerStamp->getHandler(); } return array_values(array_filter(array_unique($files))); diff --git a/src/Prime/Presenter/Adapter/HtmlPresenter.php b/src/Prime/Presenter/Adapter/HtmlPresenter.php index 40d52e81..d11b47ce 100644 --- a/src/Prime/Presenter/Adapter/HtmlPresenter.php +++ b/src/Prime/Presenter/Adapter/HtmlPresenter.php @@ -35,20 +35,20 @@ final class HtmlPresenter extends AbstractPresenter $html = << -var renderPHPNotifyNotifications = function () { +var renderPHPFlasherNotifications = function () { {$options} {$notifications} } -if ("undefined" !== typeof PHPNotify) { - PHPNotify.addStyles({$styles}, renderPHPNotifyNotifications); +if ("undefined" !== typeof PHPFlasher) { + PHPFlasher.addStyles({$styles}, renderPHPFlasherNotifications); } else { - renderPHPNotifyNotifications(); + renderPHPFlasherNotifications(); } HTML; - $this->storage->flush($envelopes); + $this->storageManager->flush($envelopes); return $html; } diff --git a/src/Prime/Presenter/Adapter/JsonPresenter.php b/src/Prime/Presenter/Adapter/JsonPresenter.php index e8eae938..3a5a88f0 100644 --- a/src/Prime/Presenter/Adapter/JsonPresenter.php +++ b/src/Prime/Presenter/Adapter/JsonPresenter.php @@ -34,7 +34,7 @@ final class JsonPresenter extends AbstractPresenter 'notifications' => $this->renderEnvelopes($envelopes), ); - $this->storage->flush($envelopes); + $this->storageManager->flush($envelopes); return $response; } diff --git a/src/Prime/Presenter/PresenterManager.php b/src/Prime/Presenter/PresenterManager.php index e7c1ccb3..6c4d2886 100644 --- a/src/Prime/Presenter/PresenterManager.php +++ b/src/Prime/Presenter/PresenterManager.php @@ -4,9 +4,6 @@ namespace Flasher\Prime\Presenter; use Flasher\Prime\Manager\AbstractManager; -/** - * @method PresenterInterface make($name = null, array $context = array()) - */ -final class PresenterManager extends AbstractManager +final class PresenterManager extends AbstractManager implements PresenterManagerInterface { } diff --git a/src/Prime/Presenter/PresenterManagerInterface.php b/src/Prime/Presenter/PresenterManagerInterface.php new file mode 100644 index 00000000..70e36067 --- /dev/null +++ b/src/Prime/Presenter/PresenterManagerInterface.php @@ -0,0 +1,27 @@ +get('drivers.notify') ); - $this->assertEquals(array('styles.css'), $config->get('drivers.notify.styles')); - $this->assertEquals(array(), $config->get('drivers.notify.options')); + $this->assertEquals(array('styles.css'), $config->get('drivers.flasher.styles')); + $this->assertEquals(array(), $config->get('drivers.flasher.options')); $this->assertEquals(null, $config->get('drivers.not_exists.options')); $this->assertEquals('now_it_exists', $config->get('drivers.not_exists.options', 'now_it_exists')); } diff --git a/src/Prime/Tests/Producer/ProducerManagerTest.php b/src/Prime/Tests/Producer/ProducerManagerTest.php index 64544c6b..ab0874a5 100644 --- a/src/Prime/Tests/Producer/ProducerManagerTest.php +++ b/src/Prime/Tests/Producer/ProducerManagerTest.php @@ -1,6 +1,6 @@ app->singleton('notify.producer.sweet_alert', function (Container $app) { - return new SweetAlertProducer($app['notify.storage'], $app['notify.middleware']); + $this->app->singleton('flasher.factory.sweet_alert', function (Container $app) { + return new SweetAlertProducer($app['flasher.storage'], $app['flasher.middleware']); }); - $this->app->singleton('notify.renderer.sweet_alert', function (Container $app) { - return new SweetAlertRenderer($app['notify.config']); + $this->app->singleton('flasher.renderer.sweet_alert', function (Container $app) { + return new SweetAlertRenderer($app['flasher.config']); }); - $this->app->alias('notify.producer.sweet_alert', 'Flasher\SweetAlert\Prime\Producer\SweetAlertProducer'); - $this->app->alias('notify.renderer.sweet_alert', 'Flasher\SweetAlert\Prime\Renderer\SweetAlertRenderer'); + $this->app->alias('flasher.factory.sweet_alert', 'Flasher\SweetAlert\Prime\Factory\SweetAlertProducer'); + $this->app->alias('flasher.renderer.sweet_alert', 'Flasher\SweetAlert\Prime\Renderer\SweetAlertRenderer'); - $this->app->extend('notify.producer', function (Flasher $manager, Container $app) { - $manager->addDriver('sweet_alert', $app['notify.producer.sweet_alert']); + $this->app->extend('flasher.factory', function (Flasher $manager, Container $app) { + $manager->addDriver('sweet_alert', $app['flasher.factory.sweet_alert']); return $manager; }); - $this->app->extend('notify.renderer', function (RendererManager $manager, Container $app) { - $manager->addDriver('sweet_alert', $app['notify.renderer.sweet_alert']); + $this->app->extend('flasher.renderer', function (RendererManager $manager, Container $app) { + $manager->addDriver('sweet_alert', $app['flasher.renderer.sweet_alert']); return $manager; }); @@ -61,10 +61,10 @@ class Laravel implements ServiceProviderInterface public function mergeConfigFromSweetAlert() { - $notifyConfig = $this->app['config']->get('notify.adapters.sweet_alert', array()); + $notifyConfig = $this->app['config']->get('flasher.adapters.sweet_alert', array()); $sweetAlertConfig = $this->app['config']->get('notify_sweet_alert', array()); - $this->app['config']->set('notify.adapters.sweet_alert', array_merge($sweetAlertConfig, $notifyConfig)); + $this->app['config']->set('flasher.adapters.sweet_alert', array_merge($sweetAlertConfig, $notifyConfig)); } } diff --git a/src/SweetAlert/Laravel/Tests/NotifySweetAlertServiceProviderTest.php b/src/SweetAlert/Laravel/Tests/NotifySweetAlertServiceProviderTest.php index 0c961030..6a418ffc 100644 --- a/src/SweetAlert/Laravel/Tests/NotifySweetAlertServiceProviderTest.php +++ b/src/SweetAlert/Laravel/Tests/NotifySweetAlertServiceProviderTest.php @@ -6,13 +6,13 @@ class NotifySweetAlertServiceProviderTest extends TestCase { public function testContainerContainNotifyServices() { - $this->assertTrue($this->app->bound('notify.producer')); - $this->assertTrue($this->app->bound('notify.producer.sweet_alert')); + $this->assertTrue($this->app->bound('flasher.factory')); + $this->assertTrue($this->app->bound('flasher.factory.sweet_alert')); } public function testNotifyFactoryIsAddedToExtensionsArray() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('drivers'); @@ -26,7 +26,7 @@ class NotifySweetAlertServiceProviderTest extends TestCase public function testConfigSweetAlertInjectedInGlobalNotifyConfig() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('config'); diff --git a/src/SweetAlert/Prime/Producer/SweetAlertProducer.php b/src/SweetAlert/Prime/Producer/SweetAlertProducer.php index 1e71a5fe..7de4427a 100644 --- a/src/SweetAlert/Prime/Producer/SweetAlertProducer.php +++ b/src/SweetAlert/Prime/Producer/SweetAlertProducer.php @@ -1,6 +1,6 @@ has('flasher.event_dispatcher')) { + return; + } + + /** @var EventDispatcherInterface $flasherBus */ + $eventDispatcher = $container->findDefinition('flasher.event_dispatcher'); + + foreach ($container->findTaggedServiceIds('flasher.event_subscriber') as $id => $tags) { + $eventDispatcher->addMethodCall('addSubscriber', array(new Reference($id))); + } + } +} diff --git a/src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php new file mode 100644 index 00000000..3fbc2a6f --- /dev/null +++ b/src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php @@ -0,0 +1,28 @@ +has('flasher.factory_manager')) { + return; + } + + /** @var Flasher $manager */ + $manager = $container->findDefinition('flasher.factory_manager'); + + foreach ($container->findTaggedServiceIds('flasher.factory') as $id => $tags) { + $manager->addMethodCall('addDriver', array(new Reference($id))); + } + } +} diff --git a/src/Symfony/DependencyInjection/Compiler/FilterCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/FilterCompilerPass.php index 38b44a55..34fc1bf7 100644 --- a/src/Symfony/DependencyInjection/Compiler/FilterCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/FilterCompilerPass.php @@ -2,6 +2,7 @@ namespace Flasher\Symfony\DependencyInjection\Compiler; +use Flasher\Prime\Filter\FilterManager; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -13,20 +14,15 @@ final class FilterCompilerPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - if (!$container->has('notify.filter')) { + if (!$container->has('flasher.filter_manager')) { return; } - /** @var \Flasher\Prime\Filter\FilterManager $manager */ - $manager = $container->findDefinition('notify.filter'); + /** @var FilterManager $manager */ + $manager = $container->findDefinition('flasher.filter_manager'); - foreach ($container->findTaggedServiceIds('notify.filter') as $id => $tags) { - foreach ($tags as $attributes) { - $manager->addMethodCall('addDriver', array( - $attributes['alias'], - new Reference($id), - )); - } + foreach ($container->findTaggedServiceIds('flasher.filter') as $id => $tags) { + $manager->addMethodCall('addDriver', array(new Reference($id))); } } } diff --git a/src/Symfony/DependencyInjection/Compiler/MiddlewareCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/MiddlewareCompilerPass.php new file mode 100644 index 00000000..6fe28fd5 --- /dev/null +++ b/src/Symfony/DependencyInjection/Compiler/MiddlewareCompilerPass.php @@ -0,0 +1,28 @@ +has('flasher.flasher_bus')) { + return; + } + + /** @var FlasherBus $flasherBus */ + $flasherBus = $container->findDefinition('flasher.flasher_bus'); + + foreach ($container->findTaggedServiceIds('flasher.middleware') as $id => $tags) { + $flasherBus->addMethodCall('addMiddleware', array(new Reference($id))); + } + } +} diff --git a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php index e7874b10..c60b6812 100644 --- a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php @@ -2,6 +2,7 @@ namespace Flasher\Symfony\DependencyInjection\Compiler; +use Flasher\Prime\Presenter\PresenterManager; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -13,20 +14,15 @@ final class PresenterCompilerPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - if (!$container->has('notify.presenter')) { + if (!$container->has('flasher.presenter_manager')) { return; } - /** @var \Flasher\Prime\Presenter\PresenterManager $manager */ - $manager = $container->findDefinition('notify.presenter'); + /** @var PresenterManager $manager */ + $manager = $container->findDefinition('flasher.presenter_manager'); - foreach ($container->findTaggedServiceIds('notify.presenter') as $id => $tags) { - foreach ($tags as $attributes) { - $manager->addMethodCall('addDriver', array( - $attributes['alias'], - new Reference($id), - )); - } + foreach ($container->findTaggedServiceIds('flasher.presenter') as $id => $tags) { + $manager->addMethodCall('addDriver', array(new Reference($id))); } } } diff --git a/src/Symfony/DependencyInjection/Compiler/ProducerCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/ProducerCompilerPass.php deleted file mode 100644 index 8356c75b..00000000 --- a/src/Symfony/DependencyInjection/Compiler/ProducerCompilerPass.php +++ /dev/null @@ -1,32 +0,0 @@ -has('notify.producer')) { - return; - } - - /** @var \Flasher\Prime\Flasher $manager */ - $manager = $container->findDefinition('notify.producer'); - - foreach ($container->findTaggedServiceIds('notify.producer') as $id => $tags) { - foreach ($tags as $attributes) { - $manager->addMethodCall('addDriver', array( - $attributes['alias'], - new Reference($id), - )); - } - } - } -} diff --git a/src/Symfony/DependencyInjection/Compiler/RendererCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/RendererCompilerPass.php index 2939f256..5f1b29b1 100644 --- a/src/Symfony/DependencyInjection/Compiler/RendererCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/RendererCompilerPass.php @@ -2,6 +2,7 @@ namespace Flasher\Symfony\DependencyInjection\Compiler; +use Flasher\Prime\Renderer\RendererManager; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -13,20 +14,15 @@ final class RendererCompilerPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - if (!$container->has('notify.renderer')) { + if (!$container->has('flasher.renderer_manager')) { return; } - /** @var \Flasher\Prime\Renderer\RendererManager $manager */ - $manager = $container->findDefinition('notify.renderer'); + /** @var RendererManager $manager */ + $manager = $container->findDefinition('flasher.renderer_manager'); - foreach ($container->findTaggedServiceIds('notify.renderer') as $id => $tags) { - foreach ($tags as $attributes) { - $manager->addMethodCall('addDriver', array( - $attributes['alias'], - new Reference($id), - )); - } + foreach ($container->findTaggedServiceIds('flasher.renderer') as $id => $tags) { + $manager->addMethodCall('addDriver', array(new Reference($id))); } } } diff --git a/src/Symfony/DependencyInjection/Configuration.php b/src/Symfony/DependencyInjection/Configuration.php index befd1f23..09be3337 100644 --- a/src/Symfony/DependencyInjection/Configuration.php +++ b/src/Symfony/DependencyInjection/Configuration.php @@ -12,13 +12,13 @@ final class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder('notify'); + $treeBuilder = new TreeBuilder('flasher'); if (\method_exists($treeBuilder, 'getRootNode')) { $rootNode = $treeBuilder->getRootNode(); } else { // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('notify'); + $rootNode = $treeBuilder->root('flasher'); } $rootNode @@ -30,7 +30,7 @@ final class Configuration implements ConfigurationInterface ->arrayNode('scripts') ->prototype('scalar')->end() ->defaultValue(array( - '/vendor/php-flasher/flasher/assets/js/notify.js' + '/bundles/flasher/js/flasher.js' )) ->end() ->arrayNode('styles') @@ -42,10 +42,6 @@ final class Configuration implements ConfigurationInterface ->useAttributeAsKey('name') ->prototype('variable')->end() ->end() - ->arrayNode('stamps_middlewares') - ->ignoreExtraKeys(false) - ->prototype('variable')->end() - ->end() ->end() ; diff --git a/src/Symfony/DependencyInjection/NotifyExtension.php b/src/Symfony/DependencyInjection/FlasherExtension.php similarity index 78% rename from src/Symfony/DependencyInjection/NotifyExtension.php rename to src/Symfony/DependencyInjection/FlasherExtension.php index ba33db63..7661e4ab 100644 --- a/src/Symfony/DependencyInjection/NotifyExtension.php +++ b/src/Symfony/DependencyInjection/FlasherExtension.php @@ -6,9 +6,8 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Flasher\Symfony\Config\Config; -final class NotifyExtension extends Extension +final class FlasherExtension extends Extension { /** * {@inheritdoc} @@ -18,12 +17,12 @@ final class NotifyExtension extends Extension public function load(array $configs, ContainerBuilder $container) { $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yaml'); + $loader->load('config.yaml'); $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $notifyConfig = $container->getDefinition('notify.config'); + $notifyConfig = $container->getDefinition('flasher.config'); $notifyConfig->replaceArgument(0, $config); } } diff --git a/src/Symfony/NotifyBundle.php b/src/Symfony/FlasherBundle.php similarity index 53% rename from src/Symfony/NotifyBundle.php rename to src/Symfony/FlasherBundle.php index cbaa07df..531fafd7 100644 --- a/src/Symfony/NotifyBundle.php +++ b/src/Symfony/FlasherBundle.php @@ -2,21 +2,25 @@ namespace Flasher\Symfony; +use Flasher\Symfony\DependencyInjection\Compiler\EventSubscriberCompilerPass; use Flasher\Symfony\DependencyInjection\Compiler\FilterCompilerPass; -use Flasher\Symfony\DependencyInjection\Compiler\ProducerCompilerPass; +use Flasher\Symfony\DependencyInjection\Compiler\FactoryCompilerPass; +use Flasher\Symfony\DependencyInjection\Compiler\MiddlewareCompilerPass; use Flasher\Symfony\DependencyInjection\Compiler\RendererCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -class NotifyBundle extends Bundle +class FlasherBundle extends Bundle { /** * {@inheritdoc} */ public function build(ContainerBuilder $container) { - $container->addCompilerPass(new ProducerCompilerPass()); + $container->addCompilerPass(new FactoryCompilerPass()); $container->addCompilerPass(new RendererCompilerPass()); $container->addCompilerPass(new FilterCompilerPass()); + $container->addCompilerPass(new MiddlewareCompilerPass()); + $container->addCompilerPass(new EventSubscriberCompilerPass()); } } diff --git a/src/Symfony/Resources/config/aliases.yaml b/src/Symfony/Resources/config/aliases.yaml new file mode 100644 index 00000000..0f601d68 --- /dev/null +++ b/src/Symfony/Resources/config/aliases.yaml @@ -0,0 +1,27 @@ +services: + Flasher\Prime\Config\Config: '@flasher.config' + Flasher\Prime\Manager\AbstractManager: '@flasher.abstract_manager' + Flasher\Prime\Flasher: '@flasher' + Flasher\Prime\Presenter\PresenterManager: '@flasher.presenter_manager' + Flasher\Prime\Renderer\RendererManager: '@flasher.renderer_manager' + Flasher\Prime\Middleware\FlasherBus: '@flasher.flasher_bus' + Flasher\Prime\EventDispatcher\EventDispatcher: '@flasher.event_dispatcher' + Flasher\Symfony\Storage\Storage: '@flasher.storage' + Flasher\Prime\Storage\StorageManager: '@flasher.storage_manager' + Flasher\Prime\Filter\FilterManager: '@flasher.filter_manager' + Flasher\Prime\Filter\FilterBuilder: '@flasher.filter_builder' + Flasher\Prime\Filter\DefaultFilter: '@flasher.filter.default' + Flasher\Prime\Factory\AbstractFactory: '@flasher.abstract_factory' + Flasher\Prime\Presenter\AbstractPresenter: '@flasher.abstract_presenter' + Flasher\Prime\Presenter\Adapter\JsonPresenter: '@flasher.presenter.json' + Flasher\Prime\Presenter\Adapter\HtmlPresenter: '@flasher.presenter.html' + + flasher.factory_manager: '@flasher' + Flasher\Prime\FlasherInterface: '@flasher' + Flasher\Prime\Storage\StorageManagerInterface: '@flasher.storage_manager' + Flasher\Prime\Renderer\RendererManagerInterface: '@flasher.renderer_manager' + Flasher\Prime\Presenter\PresenterManagerInterface: '@flasher.presenter_manager' + Flasher\Prime\Middleware\FlasherBusInterface: '@flasher.flasher_bus' + Flasher\Prime\Filter\FilterManagerInterface: '@flasher.filter_manager' + Flasher\Prime\EventDispatcher\EventDispatcherInterface: '@flasher.event_dispatcher' + Flasher\Prime\Storage\StorageInterface: '@flasher.storage' diff --git a/src/Symfony/Resources/config/config.yaml b/src/Symfony/Resources/config/config.yaml new file mode 100644 index 00000000..103377f2 --- /dev/null +++ b/src/Symfony/Resources/config/config.yaml @@ -0,0 +1,35 @@ +imports: +# - { resource: 'services.yaml' } + - { resource: 'middlewares.yaml' } + - { resource: 'storage.yaml' } + - { resource: 'presenters.yaml' } + - { resource: 'filters.yaml' } + - { resource: 'twig.yaml' } + - { resource: 'event_subscribers.yaml' } + - { resource: 'aliases.yaml' } + +services: + flasher.config: + class: Flasher\Prime\Config\Config + arguments: + - null + + flasher.abstract_manager: + class: Flasher\Prime\Manager\AbstractManager + abstract: true + arguments: + - '@flasher.config' + + flasher: + class: Flasher\Prime\Flasher + parent: 'flasher.abstract_manager' + + flasher.abstract_factory: + class: Flasher\Prime\Factory\AbstractFactory + abstract: true + arguments: + - '@flasher.event_dispatcher' + + flasher.renderer_manager: + class: Flasher\Prime\Renderer\RendererManager + parent: 'flasher.abstract_manager' diff --git a/src/Symfony/Resources/config/event_subscribers.yaml b/src/Symfony/Resources/config/event_subscribers.yaml new file mode 100644 index 00000000..32679a92 --- /dev/null +++ b/src/Symfony/Resources/config/event_subscribers.yaml @@ -0,0 +1,29 @@ +services: + flasher.event_dispatcher: + class: Flasher\Prime\EventDispatcher\EventDispatcher + + Flasher\Prime\EventDispatcher\EventListener\PostFilterListener: + public: false + tags: + - 'flasher.event_subscriber' + + Flasher\Prime\EventDispatcher\EventListener\PostFlushListener: + public: false + arguments: + - '@flasher.storage' + tags: + - 'flasher.event_subscriber' + + Flasher\Prime\EventDispatcher\EventListener\MiddlewareListener: + public: false + arguments: + - '@flasher.flasher_bus' + tags: + - 'flasher.event_subscriber' + + Flasher\Prime\EventDispatcher\EventListener\StorageListener: + public: false + arguments: + - '@flasher.storage' + tags: + - 'flasher.event_subscriber' diff --git a/src/Symfony/Resources/config/filters.yaml b/src/Symfony/Resources/config/filters.yaml new file mode 100644 index 00000000..b3b036e9 --- /dev/null +++ b/src/Symfony/Resources/config/filters.yaml @@ -0,0 +1,14 @@ +services: + flasher.filter_manager: + class: Flasher\Prime\Filter\FilterManager + parent: 'flasher.abstract_manager' + + flasher.filter_builder: + class: Flasher\Prime\Filter\FilterBuilder + + flasher.filter.default: + class: Flasher\Prime\Filter\DefaultFilter + arguments: + - '@flasher.filter_builder' + tags: + - 'flasher.filter' diff --git a/src/Symfony/Resources/config/middlewares.yaml b/src/Symfony/Resources/config/middlewares.yaml new file mode 100644 index 00000000..f628eff4 --- /dev/null +++ b/src/Symfony/Resources/config/middlewares.yaml @@ -0,0 +1,23 @@ +services: + flasher.flasher_bus: + class: Flasher\Prime\Middleware\FlasherBus + + Flasher\Prime\Middleware\AddCreatedAtStampMiddleware: + public: false + tags: + - 'flasher.middleware' + + Flasher\Prime\Middleware\AddHopsStampMiddleware: + public: false + tags: + - 'flasher.middleware' + + Flasher\Prime\Middleware\AddPriorityStampMiddleware: + public: false + tags: + - 'flasher.middleware' + + Flasher\Prime\Middleware\AddRenderedAtStampMiddleware: + public: false + tags: + - 'flasher.middleware' diff --git a/src/Symfony/Resources/config/presenters.yaml b/src/Symfony/Resources/config/presenters.yaml new file mode 100644 index 00000000..7af2bff1 --- /dev/null +++ b/src/Symfony/Resources/config/presenters.yaml @@ -0,0 +1,26 @@ +services: + flasher.presenter_manager: + class: Flasher\Prime\Presenter\PresenterManager + parent: 'flasher.abstract_manager' + + flasher.abstract_presenter: + class: Flasher\Prime\Presenter\AbstractPresenter + abstract: true + arguments: + - '@flasher.event_dispatcher' + - '@flasher.config' + - '@flasher.storage_manager' + - '@flasher.filter_manager' + - '@flasher.renderer_manager' + + flasher.presenter.html: + class: Flasher\Prime\Presenter\Adapter\HtmlPresenter + parent: 'flasher.abstract_presenter' + tags: + - 'flasher.presenter' + + flasher.presenter.json: + class: Flasher\Prime\Presenter\Adapter\JsonPresenter + parent: 'flasher.abstract_presenter' + tags: + - 'flasher.presenter' diff --git a/src/Symfony/Resources/config/services.yaml b/src/Symfony/Resources/config/services.yaml index f6bf8abb..e967a885 100644 --- a/src/Symfony/Resources/config/services.yaml +++ b/src/Symfony/Resources/config/services.yaml @@ -1,91 +1,25 @@ services: - notify.config: + flasher.config: class: Flasher\Prime\Config\Config arguments: - null - notify.producer: - class: Flasher\Prime\Producer\ProducerManager + flasher.abstract_manager: + class: Flasher\Prime\Manager\AbstractManager + abstract: true arguments: - - '@notify.config' + - '@flasher.config' - notify.presenter: - class: Flasher\Prime\Presenter\PresenterManager + flasher: + class: Flasher\Prime\Flasher + parent: 'flasher.abstract_manager' - notify.renderer: + flasher.renderer_manager: class: Flasher\Prime\Renderer\RendererManager - arguments: - - '@notify.config' + parent: 'flasher.abstract_manager' - notify.middleware: - class: Flasher\Prime\Middleware\MiddlewareManager - arguments: - - '@notify.config' - - notify.storage: - class: Flasher\Symfony\Storage\Storage - arguments: - - '@session' - - notify.filter: - class: Flasher\Prime\Filter\FilterManager - arguments: - - '@notify.config' - - notify.producer.abstract: - class: Flasher\Prime\Producer\AbstractProducer + flasher.abstract_factory: + class: Flasher\Prime\Factory\AbstractFactory abstract: true arguments: - - '@notify.storage' - - '@notify.middleware' - - notify.presenter.abstract: - class: Flasher\Prime\Presenter\AbstractPresenter - abstract: true - arguments: - - '@notify.config' - - '@notify.storage' - - '@notify.filter' - - '@notify.renderer' - - notify.presenter.html: - class: Flasher\Prime\Presenter\Adapter\HtmlPresenter - parent: 'notify.presenter.abstract' - tags: - - { name: 'notify.presenter', alias: 'html' } - - notify.presenter.json: - class: Flasher\Prime\Presenter\Adapter\JsonPresenter - parent: 'notify.presenter.abstract' - tags: - - { name: 'notify.presenter', alias: 'json' } - - notify.twig_extension: - class: Flasher\Symfony\TwigFlasher\PrimeTwigExtension - arguments: - - '@notify.presenter.html' - public: false - tags: - - { name: twig.extension } - - notify.filter_builder: - class: Flasher\Prime\Filter\FilterBuilder - - notify.filter.default: - class: Flasher\Prime\Filter\DefaultFilter - arguments: - - '@notify.filter_builder' - tags: - - { name: 'notify.filter', alias: 'default' } - - Flasher\Prime\Config\Config: '@notify.config' - Flasher\Prime\Producer\ProducerManager: '@notify.producer' - Flasher\Prime\Presenter\PresenterManager: '@notify.presenter' - Flasher\Prime\Renderer\RendererManager: '@notify.renderer' - Flasher\Prime\Middleware\MiddlewareManager: '@notify.middleware' - Flasher\Symfony\Storage\Storage: '@notify.storage' - Flasher\Prime\Filter\FilterManager: '@notify.filter' - Flasher\Prime\Filter\DefaultFilter: '@notify.filter.default' - Flasher\Prime\Filter\FilterBuilder: '@notify.filter_builder' - Flasher\Prime\Presenter\Json\JsonPresenter: '@notify.presenter.json' - Flasher\Prime\Presenter\Html\HtmlPresenter: '@notify.presenter.html' + - '@flasher.flasher_bus' diff --git a/src/Symfony/Resources/config/storage.yaml b/src/Symfony/Resources/config/storage.yaml new file mode 100644 index 00000000..6ffa1ced --- /dev/null +++ b/src/Symfony/Resources/config/storage.yaml @@ -0,0 +1,11 @@ +services: + flasher.storage: + class: Flasher\Symfony\Storage\Storage + arguments: + - '@session' + + flasher.storage_manager: + class: Flasher\Prime\Storage\StorageManager + arguments: + - '@flasher.storage' + - '@flasher.event_dispatcher' diff --git a/src/Symfony/Resources/config/twig.yaml b/src/Symfony/Resources/config/twig.yaml new file mode 100644 index 00000000..3fa176ea --- /dev/null +++ b/src/Symfony/Resources/config/twig.yaml @@ -0,0 +1,7 @@ +services: + Flasher\Symfony\Twig\FlasherTwigExtension: + class: + arguments: + - '@flasher.presenter.html' + tags: + - 'twig.extension' diff --git a/src/Symfony/Resources/public/js/flasher.js b/src/Symfony/Resources/public/js/flasher.js new file mode 100644 index 00000000..074beb38 --- /dev/null +++ b/src/Symfony/Resources/public/js/flasher.js @@ -0,0 +1,114 @@ +/*! + * PHPFlasher js 1.0.0 + * https://github.com/php-flasher/flasher + * @license MIT licensed + * + * Copyright (C) 2020 Younes KHOUBZA + */ +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + define([], factory(root)); + } else if (typeof exports === 'object') { + module.exports = factory(root); + } else { + root.PHPFlasher = factory(root); + } +})(typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this, function (window) { + + 'use strict'; + + var exports = {}; + + exports.render = function (_settings) { + var settings = Object.assign({}, { + scripts: [], + styles: [], + options: [], + notifications: [], + }, _settings); + + exports.addStyles(settings.styles, function () { + exports.addScripts(settings.scripts, function () { + var script = ''; + + settings.options.forEach(function (option) { + script += option + "\n"; + }); + + script += "\n\n"; + + settings.notifications.forEach(function (notification) { + script += notification.code + "\n"; + }); + + exports.parseScript(script); + }); + }); + }; + + exports.addStyles = function (urls, callback) { + if (0 === urls.length) { + if ("function" === typeof callback) { + callback(); + } + + return this; + } + + if (null !== document.querySelector(`link[href='${urls[0]}']`)) { + return exports.addStyles(urls.slice(1), callback); + } + + var tag = document.createElement('link'); + + tag.href = urls[0]; + tag.type = 'text/css'; + tag.rel = 'stylesheet'; + tag.onload = function () { + exports.addStyles(urls.slice(1), callback); + }; + + document.head.appendChild(tag); + + return this; + }; + + exports.addScripts = function (urls, callback) { + if (0 === urls.length) { + if ("function" === typeof callback) { + callback(); + } + + return this; + } + + if (null !== document.querySelector(`script[src='${urls[0]}']`)) { + return exports.addScripts(urls.slice(1), callback); + } + + var tag = document.createElement('script'); + + tag.src = urls[0]; + tag.type = 'text/javascript'; + tag.onload = function () { + exports.addScripts(urls.slice(1), callback); + }; + + document.body.appendChild(tag); + + return this; + }; + + exports.parseScript = function (script) { + var tag = document.createElement('script'); + + tag.type = "text/javascript"; + tag.text = script; + + document.body.appendChild(tag); + + return this; + }; + + return exports; +}); diff --git a/src/Symfony/Storage/Storage.php b/src/Symfony/Storage/Storage.php index 5913906c..6e243edb 100644 --- a/src/Symfony/Storage/Storage.php +++ b/src/Symfony/Storage/Storage.php @@ -3,79 +3,48 @@ namespace Flasher\Symfony\Storage; use Flasher\Prime\Envelope; -use Flasher\Prime\Stamp\CreatedAtStamp; -use Flasher\Prime\Stamp\LifeStamp; use Flasher\Prime\Stamp\UuidStamp; use Flasher\Prime\Storage\StorageInterface; use Symfony\Component\HttpFoundation\Session\Session; final class Storage implements StorageInterface { - const ENVELOPES_NAMESPACE = 'notify::envelopes'; + const ENVELOPES_NAMESPACE = 'flasher::envelopes'; + /** + * @var Session + */ private $session; + /** + * @param Session $session + */ public function __construct(Session $session) { $this->session = $session; } - public function get() + /** + * @inheritDoc + */ + public function all() { return $this->session->get(self::ENVELOPES_NAMESPACE, array()); } - public function add(Envelope $envelope) - { - if (null === $envelope->get('Flasher\Prime\Stamp\UuidStamp')) { - $envelope->withStamp(new UuidStamp()); - } - - if (null === $envelope->get('Flasher\Prime\Stamp\UuidStamp')) { - $envelope->withStamp(new UuidStamp()); - } - - if (null === $envelope->get('Flasher\Prime\Stamp\LifeStamp')) { - $envelope->withStamp(new LifeStamp(1)); - } - - if (null === $envelope->get('Flasher\Prime\Stamp\CreatedAtStamp')) { - $envelope->withStamp(new CreatedAtStamp()); - } - - $envelopes = $this->get(); - $envelopes[] = $envelope; - - $this->session->set(self::ENVELOPES_NAMESPACE, $envelopes); - } - /** - * @param Envelope[] $envelopes + * @inheritDoc */ - public function flush($envelopes) + public function add($envelopes) { - $envelopesMap = array(); + $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); + $envelopes = array_merge($envelopes, $this->all()); + + $store = $this->all(); foreach ($envelopes as $envelope) { - $life = $envelope->get('Flasher\Prime\Stamp\LifeStamp')->getLife(); - $uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid(); - - $envelopesMap[$uuid] = $life; - } - - $store = array(); - - foreach ($this->session->get(self::ENVELOPES_NAMESPACE, array()) as $envelope) { - $uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid(); - - if(isset($envelopesMap[$uuid])) { - $life = $envelopesMap[$uuid] - 1; - - if ($life <= 0) { - continue; - } - - $envelope->with(new LifeStamp($life)); + if (null === $envelope->get('Flasher\Prime\Stamp\UuidStamp')) { + $envelope->withStamp(new UuidStamp()); } $store[] = $envelope; @@ -83,4 +52,33 @@ final class Storage implements StorageInterface $this->session->set(self::ENVELOPES_NAMESPACE, $store); } + + /** + * @inheritDoc + */ + public function remove($envelopes) + { + $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); + + $map = UuidStamp::indexWithUuid($envelopes); + + $store = array_filter( + $this->all(), + function (Envelope $envelope) use ($map) { + $uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid(); + + return !isset($map[$uuid]); + } + ); + + $this->session->set(self::ENVELOPES_NAMESPACE, $store); + } + + /** + * @inheritDoc + */ + public function clear() + { + $this->session->set(self::ENVELOPES_NAMESPACE, array()); + } } diff --git a/src/Symfony/Twig/NotifyTwigExtension.php b/src/Symfony/Twig/FlasherTwigExtension.php similarity index 71% rename from src/Symfony/Twig/NotifyTwigExtension.php rename to src/Symfony/Twig/FlasherTwigExtension.php index 9cc18061..a7af9906 100644 --- a/src/Symfony/Twig/NotifyTwigExtension.php +++ b/src/Symfony/Twig/FlasherTwigExtension.php @@ -3,11 +3,10 @@ namespace Flasher\Symfony\Twig; use Flasher\Prime\Presenter\Adapter\HtmlPresenter; -use Flasher\Prime\Presenter\PresenterManager; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; -final class NotifyTwigExtension extends AbstractExtension +final class FlasherTwigExtension extends AbstractExtension { private $htmlPresenter; @@ -21,7 +20,7 @@ final class NotifyTwigExtension extends AbstractExtension $options = array('is_safe' => array('html')); return array( - new TwigFunction('notify_render', array($this, 'notifyRender'), $options), + new TwigFunction('flasher_render', array($this, 'flasherRender'), $options), ); } @@ -30,7 +29,7 @@ final class NotifyTwigExtension extends AbstractExtension * * @return string */ - public function notifyRender($criteria = null) + public function flasherRender($criteria = null) { return $this->htmlPresenter->render($criteria); } diff --git a/src/Toastr/Laravel/NotifyToastrServiceProvider.php b/src/Toastr/Laravel/NotifyToastrServiceProvider.php index fd4c7583..9d866f24 100644 --- a/src/Toastr/Laravel/NotifyToastrServiceProvider.php +++ b/src/Toastr/Laravel/NotifyToastrServiceProvider.php @@ -31,9 +31,9 @@ class NotifyToastrServiceProvider extends ServiceProvider public function provides() { return array( - 'notify.producer', - 'notify.producer.toastr', - 'notify.renderer.toastr', + 'flasher.factory', + 'flasher.factory.toastr', + 'flasher.renderer.toastr', ); } diff --git a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php b/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php index ed878ee7..e9631c68 100644 --- a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php +++ b/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php @@ -5,7 +5,7 @@ namespace Flasher\Toastr\Laravel\ServiceProvider\Providers; use Flasher\Prime\Flasher; use Flasher\Prime\Renderer\RendererManager; use Flasher\Toastr\LaravelFlasher\PrimeToastrServiceProvider; -use Flasher\Toastr\Prime\Producer\ToastrProducer; +use Flasher\Toastr\Prime\Factory\ToastrProducer; use Flasher\Toastr\Prime\Renderer\ToastrRenderer; use Illuminate\Container\Container; use Illuminate\Foundation\Application; @@ -35,25 +35,25 @@ class Laravel implements ServiceProviderInterface public function registerNotifyToastrServices() { - $this->app->singleton('notify.producer.toastr', function (Container $app) { - return new ToastrProducer($app['notify.storage'], $app['notify.middleware']); + $this->app->singleton('flasher.factory.toastr', function (Container $app) { + return new ToastrProducer($app['flasher.storage'], $app['flasher.middleware']); }); - $this->app->singleton('notify.renderer.toastr', function (Container $app) { - return new ToastrRenderer($app['notify.config']); + $this->app->singleton('flasher.renderer.toastr', function (Container $app) { + return new ToastrRenderer($app['flasher.config']); }); - $this->app->alias('notify.producer.toastr', 'Flasher\Toastr\Prime\Producer\ToastrProducer'); - $this->app->alias('notify.renderer.toastr', 'Flasher\Toastr\Prime\Renderer\ToastrRenderer'); + $this->app->alias('flasher.factory.toastr', 'Flasher\Toastr\Prime\Factory\ToastrProducer'); + $this->app->alias('flasher.renderer.toastr', 'Flasher\Toastr\Prime\Renderer\ToastrRenderer'); - $this->app->extend('notify.producer', function (Flasher $manager, Container $app) { - $manager->addDriver('toastr', $app['notify.producer.toastr']); + $this->app->extend('flasher.factory', function (Flasher $manager, Container $app) { + $manager->addDriver('toastr', $app['flasher.factory.toastr']); return $manager; }); - $this->app->extend('notify.renderer', function (RendererManager $manager, Container $app) { - $manager->addDriver('toastr', $app['notify.renderer.toastr']); + $this->app->extend('flasher.renderer', function (RendererManager $manager, Container $app) { + $manager->addDriver('toastr', $app['flasher.renderer.toastr']); return $manager; }); @@ -61,10 +61,10 @@ class Laravel implements ServiceProviderInterface public function mergeConfigFromToastr() { - $notifyConfig = $this->app['config']->get('notify.adapters.toastr', array()); + $notifyConfig = $this->app['config']->get('flasher.adapters.toastr', array()); $toastrConfig = $this->app['config']->get('notify_toastr', array()); - $this->app['config']->set('notify.adapters.toastr', array_merge($toastrConfig, $notifyConfig)); + $this->app['config']->set('flasher.adapters.toastr', array_merge($toastrConfig, $notifyConfig)); } } diff --git a/src/Toastr/Laravel/tests/NotifyToastrServiceProviderTest.php b/src/Toastr/Laravel/tests/NotifyToastrServiceProviderTest.php index abb20739..c37f058d 100644 --- a/src/Toastr/Laravel/tests/NotifyToastrServiceProviderTest.php +++ b/src/Toastr/Laravel/tests/NotifyToastrServiceProviderTest.php @@ -6,13 +6,13 @@ class NotifyToastrServiceProviderTest extends TestCase { public function testContainerContainNotifyServices() { - $this->assertTrue($this->app->bound('notify.producer')); - $this->assertTrue($this->app->bound('notify.producer.toastr')); + $this->assertTrue($this->app->bound('flasher.factory')); + $this->assertTrue($this->app->bound('flasher.factory.toastr')); } public function testNotifyFactoryIsAddedToExtensionsArray() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('drivers'); @@ -26,7 +26,7 @@ class NotifyToastrServiceProviderTest extends TestCase public function testConfigToastrInjectedInGlobalNotifyConfig() { - $manager = $this->app->make('notify.producer'); + $manager = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass($manager); $property = $reflection->getProperty('config'); diff --git a/src/Toastr/Prime/Producer/ToastrProducer.php b/src/Toastr/Prime/Producer/ToastrProducer.php deleted file mode 100644 index 5eebc45a..00000000 --- a/src/Toastr/Prime/Producer/ToastrProducer.php +++ /dev/null @@ -1,14 +0,0 @@ -title; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } +} diff --git a/src/Toastr/Prime/ToastrBuilder.php b/src/Toastr/Prime/ToastrBuilder.php new file mode 100644 index 00000000..17d8dfda --- /dev/null +++ b/src/Toastr/Prime/ToastrBuilder.php @@ -0,0 +1,24 @@ +envelope->getNotification(); + $notification->setTitle($title); + + return $this; + } +} diff --git a/src/Toastr/Prime/ToastrFactory.php b/src/Toastr/Prime/ToastrFactory.php new file mode 100644 index 00000000..737d57c9 --- /dev/null +++ b/src/Toastr/Prime/ToastrFactory.php @@ -0,0 +1,32 @@ +getEventDispatcher(), $this->createNotification(), 'toastr'); + } + + /** + * @inheritDoc + */ + public function supports($name = null, array $context = array()) + { + return in_array($name, array(__CLASS__, 'toastr')); + } +} diff --git a/src/Toastr/Prime/Renderer/ToastrRenderer.php b/src/Toastr/Prime/ToastrRenderer.php similarity index 65% rename from src/Toastr/Prime/Renderer/ToastrRenderer.php rename to src/Toastr/Prime/ToastrRenderer.php index 6c32905a..3474347e 100644 --- a/src/Toastr/Prime/Renderer/ToastrRenderer.php +++ b/src/Toastr/Prime/ToastrRenderer.php @@ -1,18 +1,18 @@ getContext(); - $options = isset($context['options']) ? $context['options'] : array(); + $notification = $envelope->getNotification(); + $options = $envelope->getOptions(); return sprintf( "toastr.%s('%s', '%s', %s);", - $envelope->getType(), - $envelope->getMessage(), - $envelope->getTitle(), + $notification->getType(), + $notification->getMessage(), + $notification->getTitle(), json_encode($options) ); } @@ -76,4 +76,12 @@ class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStyle { return sprintf('toastr.options = %s;', json_encode($this->options)); } + + /** + * @inheritDoc + */ + public function supports($name = null, array $context = array()) + { + return in_array($name, array(__CLASS__, 'toastr', 'Flasher\Toastr\Prime\ToastrFactory', 'Flasher\Toastr\Prime\Toastr')); + } } diff --git a/src/Toastr/Symfony/DependencyInjection/Configuration.php b/src/Toastr/Symfony/DependencyInjection/Configuration.php index 6d8cbae0..3c8e5b51 100644 --- a/src/Toastr/Symfony/DependencyInjection/Configuration.php +++ b/src/Toastr/Symfony/DependencyInjection/Configuration.php @@ -12,13 +12,13 @@ final class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder('notify_toastr'); + $treeBuilder = new TreeBuilder('flasher_toastr'); if (\method_exists($treeBuilder, 'getRootNode')) { $rootNode = $treeBuilder->getRootNode(); } else { // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('notify_toastr'); + $rootNode = $treeBuilder->root('flasher_toastr'); } $rootNode diff --git a/src/Toastr/Symfony/DependencyInjection/NotifyToastrExtension.php b/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php similarity index 85% rename from src/Toastr/Symfony/DependencyInjection/NotifyToastrExtension.php rename to src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php index 028ae226..f5bc9ba7 100644 --- a/src/Toastr/Symfony/DependencyInjection/NotifyToastrExtension.php +++ b/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -final class NotifyToastrExtension extends Extension implements PrependExtensionInterface +final class FlasherToastrExtension extends Extension implements PrependExtensionInterface { /** * {@inheritdoc} @@ -29,14 +29,14 @@ final class NotifyToastrExtension extends Extension implements PrependExtensionI */ public function prepend(ContainerBuilder $container) { - if (!$container->hasExtension('notify')) { + if (!$container->hasExtension('flasher')) { throw new \RuntimeException('[Flasher\SymfonyFlasher\PrimeBundle] is not registered'); } $configs = $container->getExtensionConfig($this->getAlias()); $config = $this->processConfiguration(new Configuration(), $configs); - $container->prependExtensionConfig('notify', array( + $container->prependExtensionConfig('flasher', array( 'adapters' => array( 'toastr' => $config, ), diff --git a/src/Toastr/Symfony/NotifyToastrBundle.php b/src/Toastr/Symfony/FlasherToastrBundle.php similarity index 69% rename from src/Toastr/Symfony/NotifyToastrBundle.php rename to src/Toastr/Symfony/FlasherToastrBundle.php index e016d65b..2e08c1eb 100644 --- a/src/Toastr/Symfony/NotifyToastrBundle.php +++ b/src/Toastr/Symfony/FlasherToastrBundle.php @@ -4,6 +4,6 @@ namespace Flasher\Toastr\Symfony; use Symfony\Component\HttpKernel\Bundle\Bundle; -class NotifyToastrBundle extends Bundle +class FlasherToastrBundle extends Bundle { } diff --git a/src/Toastr/Symfony/Resources/config/services.yaml b/src/Toastr/Symfony/Resources/config/services.yaml index f3f3d252..c2697637 100644 --- a/src/Toastr/Symfony/Resources/config/services.yaml +++ b/src/Toastr/Symfony/Resources/config/services.yaml @@ -1,16 +1,16 @@ services: - notify.producer.toastr: - parent: 'notify.producer.abstract' - class: Flasher\Toastr\Prime\Producer\ToastrProducer + flasher.factory.toastr: + parent: 'flasher.abstract_factory' + class: Flasher\Toastr\Prime\ToastrFactory tags: - - { name: 'notify.producer', alias: 'toastr' } + - { name: 'flasher.factory' } - notify.renderer.toastr: - class: Flasher\Toastr\Prime\Renderer\ToastrRenderer + flasher.renderer.toastr: + class: Flasher\Toastr\Prime\ToastrRenderer arguments: - - '@notify.config' + - '@flasher.config' tags: - - { name: 'notify.renderer', alias: 'toastr' } + - { name: 'flasher.renderer' } - Flasher\Toastr\Prime\Producer\ToastrProducer: '@notify.producer.toastr' - Flasher\Toastr\Prime\Renderer\ToastrRenderer: '@notify.renderer.toastr' + Flasher\Toastr\Prime\ToastrFactory: '@flasher.factory.toastr' + Flasher\Toastr\Prime\ToastrRenderer: '@flasher.renderer.toastr' diff --git a/src/Toastr/Symfony/composer.json b/src/Toastr/Symfony/composer.json index a231a005..ec1f9d60 100644 --- a/src/Toastr/Symfony/composer.json +++ b/src/Toastr/Symfony/composer.json @@ -1,5 +1,5 @@ { - "name": "php-flasher/flasher-symfony-toastr", + "name": "php-flasher/flasher-toastr-symfony", "type": "symfony-bundle", "description": "Symfony Flasher adapter for toastr.js library for php-flasher/flasher-symfony", "keywords": [