mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
fix event dispatcher and call the storage service
This commit is contained in:
+2
-19
@@ -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": {
|
||||
|
||||
@@ -33,7 +33,7 @@ final class NotifyServiceProvider extends ServiceProvider
|
||||
public function provides()
|
||||
{
|
||||
return array(
|
||||
'notify.producer',
|
||||
'flasher.factory',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 "<?php echo app('notify.presenter.html')->render($criteria); ?>";
|
||||
return "<?php echo app('flasher.presenter.html')->render($criteria); ?>";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, '$1<?php echo app(\'notify.presenter.html\')->render($2); ?>', $view);
|
||||
return preg_replace($pattern, '$1<?php echo app(\'flasher.presenter.html\')->render($2); ?>', $view);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ final class Laravel50 extends Laravel
|
||||
Blade::extend(function ($view, $compiler) {
|
||||
$pattern = $compiler->createPlainMatcher('notify_render(.*)');
|
||||
|
||||
return preg_replace($pattern, '$1<?php echo app(\'notify.presenter.html\')->render($2); ?>', $view);
|
||||
return preg_replace($pattern, '$1<?php echo app(\'flasher.presenter.html\')->render($2); ?>', $view);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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("<?php echo app('notify.presenter.html')->render(); ?>", $blade->compileString('@notify_render'));
|
||||
$this->assertEquals("<?php echo app('flasher.presenter.html')->render(); ?>", $blade->compileString('@notify_render'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Notyf\Prime\Producer;
|
||||
namespace Flasher\Notyf\Prime\Factory;
|
||||
|
||||
final class NotyfProducer extends \Flasher\Prime\AbstractFlasher
|
||||
{
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
services:
|
||||
notify.producer.notyf:
|
||||
parent: 'notify.producer.abstract'
|
||||
class: Flasher\Notyf\Prime\Producer\NotyfProducer
|
||||
flasher.factory.notyf:
|
||||
parent: 'flasher.factory.abstract'
|
||||
class: Flasher\Notyf\Prime\Factory\NotyfProducer
|
||||
tags:
|
||||
- { name: 'notify.producer', alias: 'notyf' }
|
||||
- { name: 'flasher.factory', alias: 'notyf' }
|
||||
|
||||
notify.renderer.notyf:
|
||||
flasher.renderer.notyf:
|
||||
class: Flasher\Notyf\Prime\Renderer\NotyfRenderer
|
||||
arguments:
|
||||
- '@notify.config'
|
||||
- '@flasher.config'
|
||||
tags:
|
||||
- { name: 'notify.renderer', alias: 'notyf' }
|
||||
- { name: 'flasher.renderer', alias: 'notyf' }
|
||||
|
||||
Flasher\Notyf\Prime\Producer\NotyfProducer: '@notify.producer.notyf'
|
||||
Flasher\Notyf\Prime\Renderer\NotyfRenderer: '@notify.renderer.notyf'
|
||||
Flasher\Notyf\Prime\Factory\NotyfProducer: '@flasher.factory.notyf'
|
||||
Flasher\Notyf\Prime\Renderer\NotyfRenderer: '@flasher.renderer.notyf'
|
||||
|
||||
@@ -31,9 +31,9 @@ class NotifyPnotifyServiceProvider extends ServiceProvider
|
||||
public function provides()
|
||||
{
|
||||
return array(
|
||||
'notify.producer',
|
||||
'notify.producer.pnotify',
|
||||
'notify.renderer.pnotify',
|
||||
'flasher.factory',
|
||||
'flasher.factory.pnotify',
|
||||
'flasher.renderer.pnotify',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,25 +35,25 @@ class Laravel implements ServiceProviderInterface
|
||||
|
||||
public function registerNotifyPnotifyServices()
|
||||
{
|
||||
$this->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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\EventDispatcher\Event;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
|
||||
final class EnvelopeDispatchedEvent
|
||||
{
|
||||
/**
|
||||
* @var Envelope
|
||||
*/
|
||||
private $envelope;
|
||||
|
||||
/**
|
||||
* @param Envelope $envelope
|
||||
*/
|
||||
public function __construct(Envelope $envelope)
|
||||
{
|
||||
$this->envelope = $envelope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Envelope
|
||||
*/
|
||||
public function getEnvelope()
|
||||
{
|
||||
return $this->envelope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Envelope $envelope
|
||||
*/
|
||||
public function setEnvelope(Envelope $envelope)
|
||||
{
|
||||
$this->envelope = $envelope;
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Flasher\Prime\EventDispatcher;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\EventSubscriber\EventSubscriberInterface;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface;
|
||||
|
||||
interface EventDispatcherInterface
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\EventDispatcher\EventSubscriber;
|
||||
namespace Flasher\Prime\EventDispatcher\EventListener;
|
||||
|
||||
interface EventSubscriberInterface
|
||||
{
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\EventDispatcher\EventListener;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\Event\EnvelopeDispatchedEvent;
|
||||
use Flasher\Prime\Middleware\FlasherBus;
|
||||
|
||||
final class MiddlewareListener implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var FlasherBus
|
||||
*/
|
||||
private $flasherBus;
|
||||
|
||||
/**
|
||||
* @param FlasherBus $flasherBus
|
||||
*/
|
||||
public function __construct(FlasherBus $flasherBus)
|
||||
{
|
||||
$this->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';
|
||||
}
|
||||
}
|
||||
+6
-9
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\EventDispatcher\EventSubscriber;
|
||||
namespace Flasher\Prime\EventDispatcher\EventListener;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\Event\PostFilterEvent;
|
||||
use Flasher\Prime\Envelope;
|
||||
|
||||
final class FilterEnvelopesByHopsListener implements EventSubscriberInterface
|
||||
final class PostFilterListener implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @param PostFilterEvent $event
|
||||
@@ -16,14 +16,11 @@ final class FilterEnvelopesByHopsListener implements EventSubscriberInterface
|
||||
{
|
||||
$envelopes = $event->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);
|
||||
}
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\EventDispatcher\EventSubscriber;
|
||||
namespace Flasher\Prime\EventDispatcher\EventListener;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\Event\PostFlushEvent;
|
||||
use Flasher\Prime\Stamp\HopsStamp;
|
||||
use Flasher\Prime\Storage\StorageInterface;
|
||||
|
||||
class RemoveRenderedEnvelopesSubscriber implements EventSubscriberInterface
|
||||
final class PostFlushListener implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var StorageInterface
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\EventDispatcher\EventListener;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\Event\EnvelopeDispatchedEvent;
|
||||
use Flasher\Prime\Storage\StorageInterface;
|
||||
|
||||
final class StorageListener implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var StorageInterface
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* @param StorageInterface $storage
|
||||
*/
|
||||
public function __construct(StorageInterface $storage)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
public function __invoke(EnvelopeDispatchedEvent $event)
|
||||
{
|
||||
$this->storage->add($event->getEnvelope());
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return 'Flasher\Prime\EventDispatcher\Event\EnvelopeDispatchedEvent';
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ namespace Flasher\Prime\Factory;
|
||||
use Flasher\Prime\Notification\NotificationBuilderInterface;
|
||||
use Flasher\Prime\Notification\NotificationInterface;
|
||||
|
||||
interface FactoryInterface
|
||||
interface FlasherFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @return NotificationBuilderInterface
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Filter;
|
||||
|
||||
interface FilterManagerInterface
|
||||
{
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return FilterInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function make($name = null, array $context = array());
|
||||
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param \Closure|FilterInterface $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDriver($driver);
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Flasher\Prime;
|
||||
|
||||
use Flasher\Prime\Factory\FlasherFactoryInterface;
|
||||
|
||||
interface FlasherInterface
|
||||
{
|
||||
/**
|
||||
@@ -10,7 +12,7 @@ interface FlasherInterface
|
||||
* @param string|null $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return NotifyFactoryInterface
|
||||
* @return FlasherFactoryInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
@@ -19,7 +21,7 @@ interface FlasherInterface
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param \Closure|NotifyFactoryInterface $driver
|
||||
* @param \Closure|FlasherFactoryInterface $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
|
||||
@@ -41,8 +41,8 @@ abstract class AbstractManager
|
||||
{
|
||||
$name = $name ?: $this->getDefaultDriver();
|
||||
|
||||
if (is_array($name)) {
|
||||
$context = $name;
|
||||
if (!is_string($name)) {
|
||||
$context = is_array($name) ? $name : array($name);
|
||||
$name = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Manager;
|
||||
|
||||
interface ManagerInterface
|
||||
{
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string|null $driver
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function make($driver = null);
|
||||
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param \Closure|object $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDriver($alias, $driver);
|
||||
}
|
||||
@@ -3,22 +3,16 @@
|
||||
namespace Flasher\Prime\Middleware;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Notification\NotificationInterface;
|
||||
|
||||
final class NotifyBus
|
||||
final class FlasherBus implements FlasherBusInterface
|
||||
{
|
||||
/**
|
||||
* @var MiddlewareInterface[]
|
||||
*/
|
||||
private $middlewares;
|
||||
private $middlewares = array();
|
||||
|
||||
/**
|
||||
* Executes the given command and optionally returns a value
|
||||
*
|
||||
* @param Envelope|NotificationInterface $envelope
|
||||
* @param array $stamps
|
||||
*
|
||||
* @return mixed
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function dispatch($envelope, $stamps = array())
|
||||
{
|
||||
@@ -32,9 +26,7 @@ final class NotifyBus
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MiddlewareInterface $middleware
|
||||
*
|
||||
* @return $this
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function addMiddleware(MiddlewareInterface $middleware)
|
||||
{
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Middleware;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Notification\NotificationInterface;
|
||||
|
||||
interface FlasherBusInterface
|
||||
{
|
||||
/**
|
||||
* Executes the given command and optionally returns a value
|
||||
*
|
||||
* @param Envelope|NotificationInterface $envelope
|
||||
* @param array $stamps
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatch($envelope, $stamps = array());
|
||||
|
||||
/**
|
||||
* @param MiddlewareInterface $middleware
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addMiddleware(MiddlewareInterface $middleware);
|
||||
}
|
||||
@@ -3,6 +3,9 @@
|
||||
namespace Flasher\Prime\Notification;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\EventDispatcher\Event\EnvelopeDispatchedEvent;
|
||||
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
|
||||
use Flasher\Prime\Stamp\HandlerStamp;
|
||||
use Flasher\Prime\Stamp\HopsStamp;
|
||||
use Flasher\Prime\Stamp\PriorityStamp;
|
||||
|
||||
@@ -14,13 +17,27 @@ class NotificationBuilder implements NotificationBuilderInterface
|
||||
protected $envelope;
|
||||
|
||||
/**
|
||||
* @param NotificationInterface|null $notification
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
public function __construct(NotificationInterface $notification = null)
|
||||
{
|
||||
$notification = $notification ?: new Notification();
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param NotificationInterface|null $notification
|
||||
* @param string $handler
|
||||
*/
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
NotificationInterface $notification = null,
|
||||
$handler = null
|
||||
) {
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -35,20 +35,20 @@ final class HtmlPresenter extends AbstractPresenter
|
||||
$html = <<<HTML
|
||||
{$scripts}
|
||||
<script type="text/javascript">
|
||||
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();
|
||||
}
|
||||
</script>
|
||||
HTML;
|
||||
|
||||
$this->storage->flush($envelopes);
|
||||
$this->storageManager->flush($envelopes);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ final class JsonPresenter extends AbstractPresenter
|
||||
'notifications' => $this->renderEnvelopes($envelopes),
|
||||
);
|
||||
|
||||
$this->storage->flush($envelopes);
|
||||
$this->storageManager->flush($envelopes);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Presenter;
|
||||
|
||||
interface PresenterManagerInterface
|
||||
{
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return PresenterInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function make($name = null, array $context = array());
|
||||
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param \Closure|PresenterInterface $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDriver($driver);
|
||||
}
|
||||
@@ -12,4 +12,12 @@ interface RendererInterface
|
||||
* @return string
|
||||
*/
|
||||
public function render(Envelope $envelope);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports($name = null, array $context = array());
|
||||
}
|
||||
|
||||
@@ -4,9 +4,6 @@ namespace Flasher\Prime\Renderer;
|
||||
|
||||
use Flasher\Prime\Manager\AbstractManager;
|
||||
|
||||
/**
|
||||
* @method RendererInterface make($name = null, array $context = array())
|
||||
*/
|
||||
class RendererManager extends AbstractManager
|
||||
final class RendererManager extends AbstractManager implements RendererManagerInterface
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Renderer;
|
||||
|
||||
interface RendererManagerInterface
|
||||
{
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return RendererInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function make($name = null, array $context = array());
|
||||
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param \Closure|RendererInterface $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDriver($driver);
|
||||
}
|
||||
@@ -6,7 +6,6 @@ use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\EventDispatcher\Event\PostFlushEvent;
|
||||
use Flasher\Prime\EventDispatcher\Event\PreFlushEvent;
|
||||
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
|
||||
use Flasher\Prime\Stamp\HopsStamp;
|
||||
|
||||
final class StorageManager implements StorageManagerInterface
|
||||
{
|
||||
|
||||
@@ -31,8 +31,8 @@ final class ConfigTest extends TestCase
|
||||
),
|
||||
$config->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'));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Producer;
|
||||
namespace Flasher\Prime\Tests\Factory;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\Event\BeforeFilter;
|
||||
use Flasher\Prime\EventDispatcher\EventDispatcher;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Stubs\Producer;
|
||||
namespace Flasher\Prime\Tests\Stubs\Factory;
|
||||
|
||||
use Flasher\Prime\AbstractFlasher;
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ class NotifySweetAlertServiceProvider extends ServiceProvider
|
||||
public function provides()
|
||||
{
|
||||
return array(
|
||||
'notify.producer',
|
||||
'notify.producer.sweet_alert',
|
||||
'notify.renderer.sweet_alert',
|
||||
'flasher.factory',
|
||||
'flasher.factory.sweet_alert',
|
||||
'flasher.renderer.sweet_alert',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Flasher\SweetAlert\Laravel\ServiceProvider\Providers;
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Renderer\RendererManager;
|
||||
use Flasher\SweetAlert\LaravelFlasher\PrimeSweetAlertServiceProvider;
|
||||
use Flasher\SweetAlert\Prime\Producer\SweetAlertProducer;
|
||||
use Flasher\SweetAlert\Prime\Factory\SweetAlertProducer;
|
||||
use Flasher\SweetAlert\Prime\Renderer\SweetAlertRenderer;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Foundation\Application;
|
||||
@@ -35,25 +35,25 @@ class Laravel implements ServiceProviderInterface
|
||||
|
||||
public function registerNotifySweetAlertServices()
|
||||
{
|
||||
$this->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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\SweetAlert\Prime\Producer;
|
||||
namespace Flasher\SweetAlert\Prime\Factory;
|
||||
|
||||
final class SweetAlertProducer extends \Flasher\Prime\AbstractFlasher
|
||||
{
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
services:
|
||||
notify.producer.sweet_alert:
|
||||
parent: 'notify.producer.abstract'
|
||||
class: Flasher\SweetAlert\Prime\Producer\SweetAlertProducer
|
||||
flasher.factory.sweet_alert:
|
||||
parent: 'flasher.factory.abstract'
|
||||
class: Flasher\SweetAlert\Prime\Factory\SweetAlertProducer
|
||||
tags:
|
||||
- { name: 'notify.producer', alias: 'sweet_alert' }
|
||||
- { name: 'flasher.factory', alias: 'sweet_alert' }
|
||||
|
||||
notify.renderer.sweet_alert:
|
||||
flasher.renderer.sweet_alert:
|
||||
class: Flasher\SweetAlert\Prime\Renderer\SweetAlertRenderer
|
||||
arguments:
|
||||
- '@notify.config'
|
||||
- '@flasher.config'
|
||||
tags:
|
||||
- { name: 'notify.renderer', alias: 'sweet_alert' }
|
||||
- { name: 'flasher.renderer', alias: 'sweet_alert' }
|
||||
|
||||
Flasher\SweetAlert\Prime\Producer\SweetAlertProducer: '@notify.producer.sweet_alert'
|
||||
Flasher\SweetAlert\Prime\Renderer\SweetAlertRenderer: '@notify.renderer.sweet_alert'
|
||||
Flasher\SweetAlert\Prime\Factory\SweetAlertProducer: '@flasher.factory.sweet_alert'
|
||||
Flasher\SweetAlert\Prime\Renderer\SweetAlertRenderer: '@flasher.renderer.sweet_alert'
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Symfony\DependencyInjection\Compiler;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class EventSubscriberCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Symfony\DependencyInjection\Compiler;
|
||||
|
||||
use Flasher\Prime\Flasher;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class FactoryCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Symfony\DependencyInjection\Compiler;
|
||||
|
||||
use Flasher\Prime\Middleware\FlasherBus;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class MiddlewareCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Symfony\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class ProducerCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->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),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
;
|
||||
|
||||
|
||||
+3
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
@@ -0,0 +1,7 @@
|
||||
services:
|
||||
Flasher\Symfony\Twig\FlasherTwigExtension:
|
||||
class:
|
||||
arguments:
|
||||
- '@flasher.presenter.html'
|
||||
tags:
|
||||
- 'twig.extension'
|
||||
@@ -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;
|
||||
});
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -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);
|
||||
}
|
||||
@@ -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',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime\Producer;
|
||||
|
||||
final class ToastrProducer extends \Flasher\Prime\AbstractFlasher
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getRenderer()
|
||||
{
|
||||
return 'toastr';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Notification\Notification;
|
||||
|
||||
final class Toastr extends Notification
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Notification\NotificationBuilder;
|
||||
|
||||
/**
|
||||
* @method Toastr getNotification()
|
||||
*/
|
||||
final class ToastrBuilder extends NotificationBuilder
|
||||
{
|
||||
/**
|
||||
* @param string $title
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function title($title)
|
||||
{
|
||||
$notification = $this->envelope->getNotification();
|
||||
$notification->setTitle($title);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Factory\AbstractFactory;
|
||||
|
||||
final class ToastrFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotification()
|
||||
{
|
||||
return new Toastr();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotificationBuilder()
|
||||
{
|
||||
return new ToastrBuilder($this->getEventDispatcher(), $this->createNotification(), 'toastr');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'toastr'));
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime\Renderer;
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Renderer\HasGlobalOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasScriptsInterface;
|
||||
use Flasher\Prime\Renderer\HasStylesInterface;
|
||||
use Flasher\Prime\Renderer\RendererInterface;
|
||||
|
||||
class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasGlobalOptionsInterface
|
||||
final class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasOptionsInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\Config\ConfigInterface
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
@@ -44,14 +44,14 @@ class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStyle
|
||||
*/
|
||||
public function render(Envelope $envelope)
|
||||
{
|
||||
$context = $envelope->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'));
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
+3
-3
@@ -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,
|
||||
),
|
||||
+1
-1
@@ -4,6 +4,6 @@ namespace Flasher\Toastr\Symfony;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class NotifyToastrBundle extends Bundle
|
||||
class FlasherToastrBundle extends Bundle
|
||||
{
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -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": [
|
||||
|
||||
Reference in New Issue
Block a user