update composer.json

This commit is contained in:
Khoubza Younes
2020-12-06 16:34:11 +01:00
parent 3a487a3702
commit 88e04e3ba1
13 changed files with 167 additions and 124 deletions
+1 -1
View File
@@ -19,6 +19,6 @@ final class Config implements ConfigInterface
public function get($key, $default = null)
{
return $this->config->get('notify'.$this->separator.$key, $default);
return $this->config->get('flasher'.$this->separator.$key, $default);
}
}
@@ -5,7 +5,7 @@ namespace Flasher\Laravel;
use Illuminate\Support\ServiceProvider;
use Flasher\Laravel\ServiceProvider\ServiceProviderManager;
final class NotifyServiceProvider extends ServiceProvider
final class FlasherServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
-4
View File
@@ -14,8 +14,4 @@ return array(
'adapters' => array(
),
'stamps_middlewares' => array(
),
);
@@ -1,5 +1,5 @@
/*!
* PHPNotify js 1.0.0
* PHPFlasher js 0.1.0
* https://github.com/php-flasher/flasher
* @license MIT licensed
*
@@ -11,7 +11,7 @@
} else if (typeof exports === 'object') {
module.exports = factory(root);
} else {
root.PHPNotify = factory(root);
root.PHPFlasher = factory(root);
}
})(typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this, function (window) {
+75 -46
View File
@@ -3,17 +3,27 @@
namespace Flasher\Laravel\ServiceProvider\Providers;
use Flasher\Laravel\Config\Config;
use Flasher\LaravelFlasher\PrimeServiceProvider;
use Flasher\Laravel\FlasherServiceProvider;
use Flasher\Laravel\Storage\Storage;
use Flasher\Prime\EventDispatcher\EventDispatcher;
use Flasher\Prime\EventDispatcher\EventListener\MiddlewareListener;
use Flasher\Prime\EventDispatcher\EventListener\PostFilterListener;
use Flasher\Prime\EventDispatcher\EventListener\PostFlushListener;
use Flasher\Prime\EventDispatcher\EventListener\StorageListener;
use Flasher\Prime\Filter\DefaultFilter;
use Flasher\Prime\Filter\FilterBuilder;
use Flasher\Prime\Filter\FilterManager;
use Flasher\Prime\Flasher;
use Flasher\Prime\Middleware\MiddlewareManager;
use Flasher\Prime\Middleware\AddCreatedAtStampMiddleware;
use Flasher\Prime\Middleware\AddDelayStampMiddleware;
use Flasher\Prime\Middleware\AddHopsStampMiddleware;
use Flasher\Prime\Middleware\AddPriorityStampMiddleware;
use Flasher\Prime\Middleware\FlasherBus;
use Flasher\Prime\Presenter\Adapter\HtmlPresenter;
use Flasher\Prime\Presenter\Adapter\JsonPresenter;
use Flasher\Prime\Presenter\PresenterManager;
use Flasher\Prime\Renderer\RendererManager;
use Flasher\Prime\Storage\StorageManager;
use Illuminate\Container\Container;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Blade;
@@ -32,21 +42,21 @@ class Laravel implements ServiceProviderInterface
return $this->app instanceof Application;
}
public function publishConfig(NotifyServiceProvider $provider)
public function publishConfig(FlasherServiceProvider $provider)
{
$source = realpath($raw = __DIR__.'/../../../resources/config/config.php') ?: $raw;
$provider->publishes(array($source => config_path('flasher.php')), 'config');
$provider->mergeConfigFrom($source, 'notify');
$provider->mergeConfigFrom($source, 'flasher');
}
public function publishAssets(NotifyServiceProvider $provider)
public function publishAssets(FlasherServiceProvider $provider)
{
$provider->publishes(array(__DIR__.'/../../../public' => public_path('vendor/php-flasher/flasher/assets/js')), 'public');
}
public function registerNotifyServices()
public function registerServices()
{
$this->app->singleton('flasher.config', function (Application $app) {
return new Config($app['config'], '.');
@@ -57,74 +67,93 @@ class Laravel implements ServiceProviderInterface
public function registerCommonServices()
{
$this->app->singleton('flasher.factory', function (Application $app) {
$this->app->singleton('flasher', function (Application $app) {
return new Flasher($app['flasher.config']);
});
$this->app->singleton('flasher.renderer_manager', function (Application $app) {
return new RendererManager($app['flasher.config']);
});
$this->app->singleton('flasher.flasher_bus', function (Application $app) {
$bus = new FlasherBus();
$bus->addMiddleware(new AddCreatedAtStampMiddleware());
$bus->addMiddleware(new AddHopsStampMiddleware());
$bus->addMiddleware(new AddPriorityStampMiddleware());
$bus->addMiddleware(new AddDelayStampMiddleware());
return $bus;
});
$this->app->singleton('flasher.storage', function (Application $app) {
return new Storage($app['session']);
});
$this->app->singleton('flasher.filter', function (Application $app) {
return new FilterManager($app['flasher.config']);
$this->app->singleton('flasher.storage_manager', function (Application $app) {
return new StorageManager($app['flasher.storage'], $app['flasher.event_dispatcher']);
});
$this->app->singleton('flasher.renderer', function (Application $app) {
return new RendererManager($app['flasher.config']);
$this->app->singleton('flasher.event_dispatcher', function (Application $app) {
$eventDispatcher = new EventDispatcher();
$eventDispatcher->addSubscriber(new PostFilterListener($app['flasher.storage']));
$eventDispatcher->addSubscriber(new PostFlushListener($app['flasher.storage']));
$eventDispatcher->addSubscriber(new MiddlewareListener($app['flasher.flasher_bus']));
$eventDispatcher->addSubscriber(new StorageListener($app['flasher.storage']));
return $eventDispatcher;
});
$this->app->singleton('flasher.presenter', function (Application $app) {
return new PresenterManager();
});
$this->app->singleton('flasher.filter_manager', function (Application $app) {
$filterManager = new FilterManager($app['flasher.config']);
$filterManager->addDriver(new DefaultFilter($app['flasher.filter_builder']));
$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('flasher.presenter.json', function (Application $app) {
return new JsonPresenter($app['flasher.config'], $app['flasher.storage'], $app['flasher.filter'], $app['flasher.renderer']);
return $filterManager;
});
$this->app->singleton('flasher.filter_builder', function (Application $app) {
return new FilterBuilder();
});
$this->app->singleton('flasher.filter.default', function (Application $app) {
return new DefaultFilter($app['flasher.filter_builder']);
$this->app->singleton('flasher.presenter_manager', function (Application $app) {
$presenterManager = new PresenterManager($app['flasher.config']);
$presenterManager->addDriver($app['flasher.presenter.html']);
$presenterManager->addDriver($app['flasher.presenter.json']);
return $presenterManager;
});
$this->app->singleton('flasher.middleware', function (Application $app) {
return new MiddlewareManager($app['flasher.config']);
$this->app->singleton('flasher.presenter.html', function (Application $app) {
return new HtmlPresenter($app['flasher.event_dispatcher'], $app['flasher.config'], $app['flasher.storage_manager'], $app['flasher.filter_manager'], $app['flasher.renderer_manager']);
});
$this->app->extend('flasher.presenter', function (PresenterManager $manager, Container $app) {
$manager->addDriver('html', $app['flasher.presenter.html']);
return $manager;
});
$this->app->extend('flasher.presenter', function (PresenterManager $manager, Container $app) {
$manager->addDriver('json', $app['flasher.presenter.json']);
return $manager;
});
$this->app->extend('flasher.filter', function (FilterManager $manager, Container $app) {
$manager->addDriver('default', $app['flasher.filter.default']);
return $manager;
$this->app->singleton('flasher.presenter.json', function (Application $app) {
return new JsonPresenter($app['flasher.event_dispatcher'], $app['flasher.config'], $app['flasher.storage_manager'], $app['flasher.filter_manager'], $app['flasher.renderer_manager']);
});
$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', 'Flasher\Prime\Flasher');
$this->app->alias('flasher.presenter_manager', 'Flasher\Prime\Presenter\PresenterManager');
$this->app->alias('flasher.renderer_manager', 'Flasher\Prime\Renderer\RendererManager');
$this->app->alias('flasher.flasher_bus', 'Flasher\Prime\Middleware\FlasherBus');
$this->app->alias('flasher.event_dispatcher', 'Flasher\Prime\EventDispatcher\EventDispatcher');
$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.storage_manager', 'Flasher\Laravel\Storage\StorageManager');
$this->app->alias('flasher.filter_manager', 'Flasher\Prime\Filter\FilterManager');
$this->app->alias('flasher.filter_builder', 'Flasher\Prime\Filter\FilterBuilder');
$this->app->alias('flasher.filter.default', 'Flasher\Prime\Filter\DefaultFilter');
$this->app->alias('flasher.presenter.html', 'Flasher\Prime\Presenter\Adapter\HtmlPresenter');
$this->app->alias('flasher.presenter.json', 'Flasher\Prime\Presenter\Adapter\JsonPresenter');
$this->app->alias('flasher', 'flasher.factory_manager');
$this->app->bind('Flasher\Prime\FlasherInterface', 'flasher');
$this->app->bind('Flasher\Prime\Storage\StorageManagerInterface', 'flasher.storage_manager');
$this->app->bind('Flasher\Prime\Renderer\RendererManagerInterface', 'flasher.renderer_manager');
$this->app->bind('Flasher\Prime\Presenter\PresenterManagerInterface', 'flasher.presenter_manager');
$this->app->bind('Flasher\Prime\Middleware\FlasherBusInterface', 'flasher.flasher_bus');
$this->app->bind('Flasher\Prime\Filter\FilterManagerInterface', 'flasher.filter_manager');
$this->app->bind('Flasher\Prime\EventDispatcher\EventDispatcherInterface', 'flasher.event_dispatcher');
$this->app->bind('Flasher\Prime\Storage\StorageInterface', 'flasher.storage');
}
public function registerBladeDirectives()
+5 -6
View File
@@ -2,11 +2,10 @@
namespace Flasher\Laravel\ServiceProvider\Providers;
use Flasher\Laravel\FlasherServiceProvider;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Blade;
use Flasher\Laravel\Config\Config;
use Flasher\LaravelFlasher\PrimeServiceProvider;
use Flasher\Prime\Middleware\MiddlewareManager;
final class Laravel4 extends Laravel
{
@@ -15,16 +14,16 @@ final class Laravel4 extends Laravel
return $this->app instanceof Application && 0 === strpos(Application::VERSION, '4.');
}
public function publishConfig(NotifyServiceProvider $provider)
public function publishConfig(FlasherServiceProvider $provider)
{
$provider->package('php-flasher/flasher-laravel', 'notify', __DIR__.'/../../../resources');
}
public function publishAssets(NotifyServiceProvider $provider)
public function publishAssets(FlasherServiceProvider $provider)
{
}
public function registerNotifyServices()
public function registerServices()
{
$this->app->singleton('flasher.config', function (Application $app) {
return new Config($app['config'], '::');
@@ -36,7 +35,7 @@ final class Laravel4 extends Laravel
public function registerBladeDirectives()
{
Blade::extend(function ($view, $compiler) {
$pattern = $compiler->createPlainMatcher('notify_render(.*)');
$pattern = $compiler->createPlainMatcher('flasher_render(.*)');
return preg_replace($pattern, '$1<?php echo app(\'flasher.presenter.html\')->render($2); ?>', $view);
});
+1 -1
View File
@@ -15,7 +15,7 @@ final class Laravel50 extends Laravel
public function registerBladeDirectives()
{
Blade::extend(function ($view, $compiler) {
$pattern = $compiler->createPlainMatcher('notify_render(.*)');
$pattern = $compiler->createPlainMatcher('flasher_render(.*)');
return preg_replace($pattern, '$1<?php echo app(\'flasher.presenter.html\')->render($2); ?>', $view);
});
+2 -2
View File
@@ -21,11 +21,11 @@ final class Lumen extends Laravel
$provider->mergeConfigFrom($source, 'notify');
}
public function registerNotifyServices()
public function registerServices()
{
$this->app->register('\Illuminate\Session\SessionServiceProvider');
$this->app->configure('session');
parent::registerNotifyServices();
parent::registerServices();
}
}
@@ -2,17 +2,17 @@
namespace Flasher\Laravel\ServiceProvider\Providers;
use Flasher\LaravelFlasher\PrimeServiceProvider;
use Flasher\Laravel\FlasherServiceProvider;
interface ServiceProviderInterface
{
public function shouldBeUsed();
public function publishConfig(NotifyServiceProvider $provider);
public function publishConfig(FlasherServiceProvider $provider);
public function publishAssets(NotifyServiceProvider $provider);
public function publishAssets(FlasherServiceProvider $provider);
public function registerNotifyServices();
public function registerServices();
public function registerBladeDirectives();
}
+3 -2
View File
@@ -2,6 +2,7 @@
namespace Flasher\Laravel\ServiceProvider;
use Flasher\Laravel\FlasherServiceProvider;
use Flasher\LaravelFlasher\PrimeServiceProvider;
use Flasher\Laravel\ServiceProvider\Providers\ServiceProviderInterface;
@@ -21,7 +22,7 @@ final class ServiceProviderManager
private $notifyServiceProvider;
public function __construct(NotifyServiceProvider $notifyServiceProvider)
public function __construct(FlasherServiceProvider $notifyServiceProvider)
{
$this->notifyServiceProvider = $notifyServiceProvider;
}
@@ -38,7 +39,7 @@ final class ServiceProviderManager
public function register()
{
$provider = $this->resolveServiceProvider();
$provider->registerNotifyServices();
$provider->registerServices();
}
/**
+64 -46
View File
@@ -3,78 +3,45 @@
namespace Flasher\Laravel\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;
final class Storage implements StorageInterface
{
const ENVELOPES_NAMESPACE = 'notify::envelopes';
const ENVELOPES_NAMESPACE = 'flasher::envelopes';
/**
* @var \Illuminate\Session\SessionManager|\Illuminate\Session\Store
*/
private $session;
/**
* @param \Illuminate\Session\SessionManager|\Illuminate\Session\Store $session
*/
public function __construct($session)
{
$this->session = $session;
}
/**
* @inheritDoc
*/
public function get()
{
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\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->put(self::ENVELOPES_NAMESPACE, $envelopes);
}
/**
* @param \Flasher\Prime\Envelope[] $envelopes
* @inheritDoc
*/
public function flush($envelopes)
public function add($envelopes)
{
$envelopesMap = array();
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
$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;
@@ -82,4 +49,55 @@ final class Storage implements StorageInterface
$this->session->put(self::ENVELOPES_NAMESPACE, $store);
}
/**
* @inheritDoc
*/
public function update($envelopes)
{
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
$map = UuidStamp::indexWithUuid($envelopes);
$store = $this->all();
foreach ($store as $index => $envelope) {
$uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid();
if (!isset($map[$uuid])) {
continue;
}
$store[$index] = $map[$uuid];
}
$this->session->put(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->put(self::ENVELOPES_NAMESPACE, $store);
}
/**
* @inheritDoc
*/
public function clear()
{
$this->session->set(self::ENVELOPES_NAMESPACE, array());
}
}
+7 -7
View File
@@ -28,16 +28,16 @@
"license": "MIT",
"require": {
"php": ">=5.3",
"illuminate/support": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0",
"php-flasher/flasher": "^1.0"
"illuminate/support": "^4.0|^5.0|^6.0|^7.0|^8.0",
"php-flasher/flasher": "dev-main"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.0 || ^7.0 || ^8.3 || ^9.0",
"orchestra/testbench": "^2.0 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
"phpunit/phpunit": "^4.8|^5.7|^6.0|^7.0|^8.3|^9.0",
"orchestra/testbench": "^2.0|^3.0|^4.0|^5.0|^6.0"
},
"autoload": {
"psr-4": {
"Flasher\\Laravel\\": "src/"
"Flasher\\Laravel\\": ""
},
"files": [
"helpers.php"
@@ -45,13 +45,13 @@
},
"autoload-dev": {
"psr-4": {
"Flasher\\Laravel\\Tests\\": "tests/"
"Flasher\\Laravel\\Tests\\": "Tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Flasher\\Laravel\Flasher\PrimeServiceProvider"
"Flasher\\Laravel\\FlasherServiceProvider"
],
"aliases": {
"Flasher": "Flasher\\Laravel\\Facades\\Flasher"
+2 -2
View File
@@ -1,6 +1,6 @@
<?php
if (!function_exists('notify')) {
if (!function_exists('flasher')) {
/**
* @param string $message
* @param string $type
@@ -10,7 +10,7 @@ if (!function_exists('notify')) {
*
* @return \Flasher\Prime\Flasher
*/
function notify($message = null, $type = 'success', $title = '', array $options = array(), array $stamps = array())
function flasher($message = null, $type = 'success', $title = '', array $options = array(), array $stamps = array())
{
if (is_null($message) && 0 === func_num_args()) {
return app('flasher.factory');