From 3a487a37023e90197b52b45a1df2479cfeca0502 Mon Sep 17 00:00:00 2001 From: Khoubza Younes Date: Sun, 6 Dec 2020 04:03:14 +0100 Subject: [PATCH] fix event dispatcher and call the storage service --- NotifyServiceProvider.php | 2 +- Resources/config/config.php | 2 +- ServiceProvider/Providers/Laravel.php | 72 ++++++++++++------------- ServiceProvider/Providers/Laravel4.php | 4 +- ServiceProvider/Providers/Laravel50.php | 2 +- Tests/NotifyServiceProviderTest.php | 6 +-- helpers.php | 4 +- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/NotifyServiceProvider.php b/NotifyServiceProvider.php index c929acb3..df899f58 100644 --- a/NotifyServiceProvider.php +++ b/NotifyServiceProvider.php @@ -33,7 +33,7 @@ final class NotifyServiceProvider extends ServiceProvider public function provides() { return array( - 'notify.producer', + 'flasher.factory', ); } diff --git a/Resources/config/config.php b/Resources/config/config.php index 9e46f6d2..3b6fa8af 100644 --- a/Resources/config/config.php +++ b/Resources/config/config.php @@ -4,7 +4,7 @@ return array( 'default' => 'toastr', 'scripts' => array( - '/vendor/php-flasher/flasher/assets/js/notify.js' + '/vendor/php-flasher/flasher/assets/js/flasher.js' ), 'styles' => array( diff --git a/ServiceProvider/Providers/Laravel.php b/ServiceProvider/Providers/Laravel.php index 61049ef7..b5a1b172 100644 --- a/ServiceProvider/Providers/Laravel.php +++ b/ServiceProvider/Providers/Laravel.php @@ -36,7 +36,7 @@ class Laravel implements ServiceProviderInterface { $source = realpath($raw = __DIR__.'/../../../resources/config/config.php') ?: $raw; - $provider->publishes(array($source => config_path('notify.php')), 'config'); + $provider->publishes(array($source => config_path('flasher.php')), 'config'); $provider->mergeConfigFrom($source, 'notify'); } @@ -48,7 +48,7 @@ class Laravel implements ServiceProviderInterface public function registerNotifyServices() { - $this->app->singleton('notify.config', function (Application $app) { + $this->app->singleton('flasher.config', function (Application $app) { return new Config($app['config'], '.'); }); @@ -57,80 +57,80 @@ class Laravel implements ServiceProviderInterface public function registerCommonServices() { - $this->app->singleton('notify.producer', function (Application $app) { - return new Flasher($app['notify.config']); + $this->app->singleton('flasher.factory', function (Application $app) { + return new Flasher($app['flasher.config']); }); - $this->app->singleton('notify.storage', function (Application $app) { + $this->app->singleton('flasher.storage', function (Application $app) { return new Storage($app['session']); }); - $this->app->singleton('notify.filter', function (Application $app) { - return new FilterManager($app['notify.config']); + $this->app->singleton('flasher.filter', function (Application $app) { + return new FilterManager($app['flasher.config']); }); - $this->app->singleton('notify.renderer', function (Application $app) { - return new RendererManager($app['notify.config']); + $this->app->singleton('flasher.renderer', function (Application $app) { + return new RendererManager($app['flasher.config']); }); - $this->app->singleton('notify.presenter', function (Application $app) { + $this->app->singleton('flasher.presenter', function (Application $app) { return new PresenterManager(); }); - $this->app->singleton('notify.presenter.html', function (Application $app) { - return new HtmlPresenter($app['notify.config'], $app['notify.storage'], $app['notify.filter'], $app['notify.renderer']); + $this->app->singleton('flasher.presenter.html', function (Application $app) { + return new HtmlPresenter($app['flasher.config'], $app['flasher.storage'], $app['flasher.filter'], $app['flasher.renderer']); }); - $this->app->singleton('notify.presenter.json', function (Application $app) { - return new JsonPresenter($app['notify.config'], $app['notify.storage'], $app['notify.filter'], $app['notify.renderer']); + $this->app->singleton('flasher.presenter.json', function (Application $app) { + return new JsonPresenter($app['flasher.config'], $app['flasher.storage'], $app['flasher.filter'], $app['flasher.renderer']); }); - $this->app->singleton('notify.filter_builder', function (Application $app) { + $this->app->singleton('flasher.filter_builder', function (Application $app) { return new FilterBuilder(); }); - $this->app->singleton('notify.filter.default', function (Application $app) { - return new DefaultFilter($app['notify.filter_builder']); + $this->app->singleton('flasher.filter.default', function (Application $app) { + return new DefaultFilter($app['flasher.filter_builder']); }); - $this->app->singleton('notify.middleware', function (Application $app) { - return new MiddlewareManager($app['notify.config']); + $this->app->singleton('flasher.middleware', function (Application $app) { + return new MiddlewareManager($app['flasher.config']); }); - $this->app->extend('notify.presenter', function (PresenterManager $manager, Container $app) { - $manager->addDriver('html', $app['notify.presenter.html']); + $this->app->extend('flasher.presenter', function (PresenterManager $manager, Container $app) { + $manager->addDriver('html', $app['flasher.presenter.html']); return $manager; }); - $this->app->extend('notify.presenter', function (PresenterManager $manager, Container $app) { - $manager->addDriver('json', $app['notify.presenter.json']); + $this->app->extend('flasher.presenter', function (PresenterManager $manager, Container $app) { + $manager->addDriver('json', $app['flasher.presenter.json']); return $manager; }); - $this->app->extend('notify.filter', function (FilterManager $manager, Container $app) { - $manager->addDriver('default', $app['notify.filter.default']); + $this->app->extend('flasher.filter', function (FilterManager $manager, Container $app) { + $manager->addDriver('default', $app['flasher.filter.default']); return $manager; }); - $this->app->alias('notify.config', 'Flasher\Laravel\Config\Config'); - $this->app->alias('notify.producer', 'Flasher\Prime\Flasher'); - $this->app->alias('notify.presenter', 'Flasher\Prime\Presenter\PresenterManager'); - $this->app->alias('notify.middleware', 'Flasher\Prime\Middleware\MiddlewareManager'); - $this->app->alias('notify.storage', 'Flasher\Laravel\Storage\Storage'); - $this->app->alias('notify.filter', 'Flasher\Prime\Filter\FilterManager'); - $this->app->alias('notify.presenter.html', 'Flasher\Prime\Presenter\Adapter\HtmlPresenter'); - $this->app->alias('notify.presenter.json', 'Flasher\Prime\Presenter\Adapter\JsonPresenter'); - $this->app->alias('notify.filter_builder', 'Flasher\Prime\Filter\FilterBuilder'); - $this->app->alias('notify.filter.default', 'Flasher\Prime\Filter\DefaultFilter'); + $this->app->alias('flasher.config', 'Flasher\Laravel\Config\Config'); + $this->app->alias('flasher.factory', 'Flasher\Prime\Flasher'); + $this->app->alias('flasher.presenter', 'Flasher\Prime\Presenter\PresenterManager'); + $this->app->alias('flasher.middleware', 'Flasher\Prime\Middleware\MiddlewareManager'); + $this->app->alias('flasher.storage', 'Flasher\Laravel\Storage\Storage'); + $this->app->alias('flasher.filter', 'Flasher\Prime\Filter\FilterManager'); + $this->app->alias('flasher.presenter.html', 'Flasher\Prime\Presenter\Adapter\HtmlPresenter'); + $this->app->alias('flasher.presenter.json', 'Flasher\Prime\Presenter\Adapter\JsonPresenter'); + $this->app->alias('flasher.filter_builder', 'Flasher\Prime\Filter\FilterBuilder'); + $this->app->alias('flasher.filter.default', 'Flasher\Prime\Filter\DefaultFilter'); } public function registerBladeDirectives() { Blade::directive('notify_render', function ($criteria = null) { - return "render($criteria); ?>"; + return "render($criteria); ?>"; }); } } diff --git a/ServiceProvider/Providers/Laravel4.php b/ServiceProvider/Providers/Laravel4.php index 378e42d8..1adab6a1 100644 --- a/ServiceProvider/Providers/Laravel4.php +++ b/ServiceProvider/Providers/Laravel4.php @@ -26,7 +26,7 @@ final class Laravel4 extends Laravel public function registerNotifyServices() { - $this->app->singleton('notify.config', function (Application $app) { + $this->app->singleton('flasher.config', function (Application $app) { return new Config($app['config'], '::'); }); @@ -38,7 +38,7 @@ final class Laravel4 extends Laravel Blade::extend(function ($view, $compiler) { $pattern = $compiler->createPlainMatcher('notify_render(.*)'); - return preg_replace($pattern, '$1render($2); ?>', $view); + return preg_replace($pattern, '$1render($2); ?>', $view); }); } } diff --git a/ServiceProvider/Providers/Laravel50.php b/ServiceProvider/Providers/Laravel50.php index 3f0b8702..d129a0ae 100644 --- a/ServiceProvider/Providers/Laravel50.php +++ b/ServiceProvider/Providers/Laravel50.php @@ -17,7 +17,7 @@ final class Laravel50 extends Laravel Blade::extend(function ($view, $compiler) { $pattern = $compiler->createPlainMatcher('notify_render(.*)'); - return preg_replace($pattern, '$1render($2); ?>', $view); + return preg_replace($pattern, '$1render($2); ?>', $view); }); } } diff --git a/Tests/NotifyServiceProviderTest.php b/Tests/NotifyServiceProviderTest.php index 14b431a5..2e551678 100644 --- a/Tests/NotifyServiceProviderTest.php +++ b/Tests/NotifyServiceProviderTest.php @@ -8,12 +8,12 @@ class NotifyServiceProviderTest extends TestCase { public function test_notify_service_exists() { - $this->assertTrue($this->app->bound('notify.producer')); + $this->assertTrue($this->app->bound('flasher.factory')); } public function test_notify_manager_get_config() { - $notify = $this->app->make('notify.producer'); + $notify = $this->app->make('flasher.factory'); $reflection = new \ReflectionClass(get_class($notify)); $config = $reflection->getProperty('config'); @@ -27,6 +27,6 @@ class NotifyServiceProviderTest extends TestCase /** @var BladeCompiler $blade */ $blade = $this->app->make('view')->getEngineResolver()->resolve('blade')->getCompiler(); - $this->assertEquals("render(); ?>", $blade->compileString('@notify_render')); + $this->assertEquals("render(); ?>", $blade->compileString('@notify_render')); } } diff --git a/helpers.php b/helpers.php index b86eccc9..683e4a49 100644 --- a/helpers.php +++ b/helpers.php @@ -13,9 +13,9 @@ if (!function_exists('notify')) { function notify($message = null, $type = 'success', $title = '', array $options = array(), array $stamps = array()) { if (is_null($message) && 0 === func_num_args()) { - return app('notify.producer'); + return app('flasher.factory'); } - return app('notify.producer')->render($type, $message, $title, $options, $stamps); + return app('flasher.factory')->render($type, $message, $title, $options, $stamps); } }