mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
update laravel and js files
This commit is contained in:
@@ -10,7 +10,6 @@ use Flasher\Prime\EventDispatcher\EventListener\StampsListener;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\FilterListener;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\RemoveListener;
|
||||
use Flasher\Prime\Filter\Filter;
|
||||
use Flasher\Prime\Filter\FilterBuilder;
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Renderer\Renderer;
|
||||
use Flasher\Prime\Storage\StorageManager;
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
namespace Flasher\Noty\Laravel\ServiceProvider\Providers;
|
||||
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Renderer\RendererManager;
|
||||
use Flasher\Noty\Laravel\FlasherNotyServiceProvider;
|
||||
use Flasher\Noty\Prime\NotyFactory;
|
||||
use Flasher\Noty\Prime\NotyRenderer;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
@@ -35,28 +33,17 @@ class Laravel implements ServiceProviderInterface
|
||||
|
||||
public function registerServices()
|
||||
{
|
||||
$this->app->singleton('flasher.factory.noty', function (Container $app) {
|
||||
return new NotyFactory($app['flasher.event_dispatcher']);
|
||||
$this->app->singleton('flasher.noty', function (Container $app) {
|
||||
return new NotyFactory($app['flasher.storage_manager']);
|
||||
});
|
||||
|
||||
$this->app->singleton('flasher.renderer.noty', function (Container $app) {
|
||||
return new NotyRenderer($app['flasher.config']);
|
||||
});
|
||||
|
||||
$this->app->alias('flasher.factory.noty', 'Flasher\Noty\Prime\NotyFactory');
|
||||
$this->app->alias('flasher.renderer.noty', 'Flasher\Noty\Prime\NotyRenderer');
|
||||
$this->app->alias('flasher.noty', 'Flasher\Noty\Prime\NotyFactory');
|
||||
|
||||
$this->app->extend('flasher', function (Flasher $flasher, Container $app) {
|
||||
$flasher->addFactory($app['flasher.factory.noty']);
|
||||
$flasher->addFactory('toastr', $app['flasher.noty']);
|
||||
|
||||
return $flasher;
|
||||
});
|
||||
|
||||
$this->app->extend('flasher.renderer_manager', function (RendererManager $manager, Container $app) {
|
||||
$manager->addDriver($app['flasher.renderer.noty']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
}
|
||||
|
||||
public function mergeConfigFromNoty()
|
||||
|
||||
@@ -102,6 +102,7 @@ final class NotyBuilder extends NotificationBuilder
|
||||
|
||||
/**
|
||||
* @param string $option
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
|
||||
@@ -3,49 +3,17 @@
|
||||
namespace Flasher\Noty\Prime;
|
||||
|
||||
use Flasher\Prime\Factory\AbstractFactory;
|
||||
use Flasher\Prime\Notification\NotificationBuilderInterface;
|
||||
use Flasher\Prime\Stamp\StampInterface;
|
||||
|
||||
/**
|
||||
* @method NotyBuilder type(string $type, string $message = null, array $options = array())
|
||||
* @method NotyBuilder message(string $message)
|
||||
* @method NotyBuilder options(array $options, bool $merge = true)
|
||||
* @method NotyBuilder setOption(string $name, $value)
|
||||
* @method NotyBuilder unsetOption(string $name)
|
||||
* @method NotyBuilder priority(int $priority)
|
||||
* @method NotyBuilder handler(string $handler)
|
||||
* @method NotyBuilder with(StampInterface[] $stamps)
|
||||
* @method NotyBuilder withStamp(StampInterface $stamp)
|
||||
* @method NotyBuilder hops(int $amount)
|
||||
* @method NotyBuilder keep()
|
||||
* @method NotyBuilder success(string $message = null, array $options = array())
|
||||
* @method NotyBuilder error(string $message = null, array $options = array())
|
||||
* @method NotyBuilder info(string $message = null, array $options = array())
|
||||
* @method NotyBuilder warning(string $message = null, array $options = array())
|
||||
* @mixin NotyBuilder
|
||||
*/
|
||||
final class NotyFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotification()
|
||||
{
|
||||
return new Noty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotificationBuilder()
|
||||
{
|
||||
return new NotyBuilder($this->getStorageManager(), $this->createNotification(), 'noty');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'noty'));
|
||||
return new NotyBuilder($this->getStorageManager(), new Noty(), 'noty');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Noty\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Renderer\HasOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasScriptsInterface;
|
||||
use Flasher\Prime\Renderer\HasStylesInterface;
|
||||
use Flasher\Prime\Renderer\RendererInterface;
|
||||
|
||||
final class NotyRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasOptionsInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $scripts;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $styles;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
public function __construct(ConfigInterface $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->scripts = $config->get('adapters.noty.scripts', array());
|
||||
$this->styles = $config->get('adapters.noty.styles', array());
|
||||
$this->options = $config->get('adapters.noty.options', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function render(Envelope $envelope)
|
||||
{
|
||||
$notification = $envelope->getNotification();
|
||||
$options = $envelope->getOptions();
|
||||
|
||||
$options['text'] = $envelope->getMessage();
|
||||
$options['type'] = $envelope->getType();
|
||||
|
||||
return sprintf("new Noty(%s).show();", json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getScripts()
|
||||
{
|
||||
return $this->scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getStyles()
|
||||
{
|
||||
return $this->styles;
|
||||
}
|
||||
|
||||
public function renderOptions()
|
||||
{
|
||||
return sprintf('Noty.overrideDefaults(%s);', json_encode($this->options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'noty', 'Flasher\Noty\Prime\NotyFactory', 'Flasher\Noty\Prime\Noty'));
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ final class Configuration implements ConfigurationInterface
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array(
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.js',
|
||||
'/bundles/flashernoty/flasher-noty.js',
|
||||
))
|
||||
->end()
|
||||
->arrayNode('styles')
|
||||
|
||||
@@ -30,7 +30,7 @@ final class FlasherNotyExtension extends Extension implements PrependExtensionIn
|
||||
public function prepend(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasExtension('flasher')) {
|
||||
throw new \RuntimeException('[Flasher\SymfonyFlasher\PrimeBundle] is not registered');
|
||||
throw new \RuntimeException('[Flasher\Symfony\FlasherBundle] is not registered');
|
||||
}
|
||||
|
||||
$configs = $container->getExtensionConfig($this->getAlias());
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
services:
|
||||
flasher.factory.noty:
|
||||
flasher.noty:
|
||||
parent: 'flasher.abstract_factory'
|
||||
class: Flasher\Noty\Prime\NotyFactory
|
||||
tags:
|
||||
- { name: 'flasher.factory' }
|
||||
- { name: 'flasher.factory', alias: 'noty' }
|
||||
|
||||
flasher.renderer.noty:
|
||||
class: Flasher\Noty\Prime\NotyRenderer
|
||||
arguments:
|
||||
- '@flasher.config'
|
||||
tags:
|
||||
- { name: 'flasher.renderer' }
|
||||
|
||||
Flasher\Noty\Prime\NotyFactory: '@flasher.factory.noty'
|
||||
Flasher\Noty\Prime\NotyRenderer: '@flasher.renderer.noty'
|
||||
Flasher\Noty\Prime\NotyFactory: '@flasher.noty'
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
PHPFlasher.addFactory('notyf', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
|
||||
exports.render = function (data) {
|
||||
window.notyf.open(data);
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
if ("undefined" === typeof window.notyf) {
|
||||
window.notyf = new Notyf(options);
|
||||
}
|
||||
};
|
||||
|
||||
return exports;
|
||||
})());
|
||||
@@ -4,9 +4,7 @@ namespace Flasher\Notyf\Laravel\ServiceProvider\Providers;
|
||||
|
||||
use Flasher\Notyf\Laravel\FlasherNotyfServiceProvider;
|
||||
use Flasher\Notyf\Prime\NotyfFactory;
|
||||
use Flasher\Notyf\Prime\NotyfRenderer;
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Renderer\RendererManager;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
@@ -36,24 +34,13 @@ class Laravel implements ServiceProviderInterface
|
||||
public function registerServices()
|
||||
{
|
||||
$this->app->singleton('flasher.factory.notyf', function (Container $app) {
|
||||
return new NotyfFactory($app['flasher.event_dispatcher']);
|
||||
return new NotyfFactory($app['flasher.storage_manager']);
|
||||
});
|
||||
|
||||
$this->app->singleton('flasher.renderer.notyf', function (Container $app) {
|
||||
return new NotyfRenderer($app['flasher.config']);
|
||||
});
|
||||
|
||||
$this->app->alias('flasher.factory.notyf', 'Flasher\Notyf\Prime\NotyfFactory');
|
||||
$this->app->alias('flasher.renderer.notyf', 'Flasher\Notyf\Prime\NotyfRenderer');
|
||||
$this->app->alias('flasher.notyf', 'Flasher\Notyf\Prime\NotyfFactory');
|
||||
|
||||
$this->app->extend('flasher', function (Flasher $manager, Container $app) {
|
||||
$manager->addFactory($app['flasher.factory.notyf']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
|
||||
$this->app->extend('flasher.renderer_manager', function (RendererManager $manager, Container $app) {
|
||||
$manager->addDriver($app['flasher.renderer.notyf']);
|
||||
$manager->addFactory('notyf', $app['flasher.notyf']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
|
||||
@@ -6,5 +6,4 @@ use Flasher\Prime\Notification\Notification;
|
||||
|
||||
final class Notyf extends Notification
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,6 @@ namespace Flasher\Notyf\Prime;
|
||||
|
||||
use Flasher\Prime\Notification\NotificationBuilder;
|
||||
|
||||
/**
|
||||
* @method Pnotify getNotification()
|
||||
*/
|
||||
final class NotyfBuilder extends NotificationBuilder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,29 +4,16 @@ namespace Flasher\Notyf\Prime;
|
||||
|
||||
use Flasher\Prime\Factory\AbstractFactory;
|
||||
|
||||
/**
|
||||
* @mixin NotyfBuilder
|
||||
*/
|
||||
final class NotyfFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotification()
|
||||
{
|
||||
return new Pnotify();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotificationBuilder()
|
||||
{
|
||||
return new PnotifyBuilder($this->getStorageManager(), $this->createNotification(), 'notyf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'notyf'));
|
||||
return new NotyfBuilder($this->getStorageManager(), new Notyf(), 'notyf');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Notyf\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Renderer\HasOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasScriptsInterface;
|
||||
use Flasher\Prime\Renderer\HasStylesInterface;
|
||||
use Flasher\Prime\Renderer\RendererInterface;
|
||||
|
||||
final class NotyfRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasOptionsInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $scripts;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $styles;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
public function __construct(ConfigInterface $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->scripts = $config->get('adapters.notyf.scripts', array());
|
||||
$this->styles = $config->get('adapters.notyf.styles', array());
|
||||
$this->options = $config->get('adapters.notyf.options', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function render(Envelope $envelope)
|
||||
{
|
||||
$options = $envelope->getOptions();
|
||||
|
||||
$options['message'] = $envelope->getMessage();
|
||||
$options['type'] = $envelope->getType();
|
||||
|
||||
return sprintf("notyf.open(%s);", json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getScripts()
|
||||
{
|
||||
return $this->scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getStyles()
|
||||
{
|
||||
return $this->styles;
|
||||
}
|
||||
|
||||
public function renderOptions()
|
||||
{
|
||||
return sprintf('if ("undefined" === typeof notyf) { var notyf = new Notyf(%s); }', json_encode($this->options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'notyf', 'Flasher\Notyf\Prime\NotyfFactory',
|
||||
'Flasher\Notyf\Prime\Pnotify'
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ final class Configuration implements ConfigurationInterface
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array(
|
||||
'https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js',
|
||||
'/bundles/flashernotyf/flasher-notyf.js',
|
||||
))
|
||||
->end()
|
||||
->arrayNode('styles')
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
services:
|
||||
flasher.factory.notyf:
|
||||
flasher.notyf:
|
||||
parent: 'flasher.abstract_factory'
|
||||
class: Flasher\Notyf\Prime\NotyfProducer
|
||||
class: Flasher\Notyf\Prime\NotyfFactory
|
||||
tags:
|
||||
- { name: 'flasher.factory' }
|
||||
- { name: 'flasher.factory', alias: 'notyf' }
|
||||
|
||||
flasher.renderer.notyf:
|
||||
class: Flasher\Notyf\Prime\NotyfRenderer
|
||||
arguments:
|
||||
- '@flasher.config'
|
||||
tags:
|
||||
- { name: 'flasher.renderer' }
|
||||
|
||||
Flasher\Notyf\Prime\NotyfProducer: '@flasher.factory.notyf'
|
||||
Flasher\Notyf\Prime\NotyfRenderer: '@flasher.renderer.notyf'
|
||||
Flasher\Notyf\Prime\NotyfFactory: '@flasher.notyf'
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
PHPFlasher.addFactory('notyf', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
|
||||
exports.render = function (data) {
|
||||
window.notyf.open(data);
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
if ("undefined" === typeof window.notyf) {
|
||||
window.notyf = new Notyf(options);
|
||||
}
|
||||
};
|
||||
|
||||
return exports;
|
||||
})());
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
PHPFlasher.addFactory('noty', (function () {
|
||||
PHPFlasher.addFactory('pnotify', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
@@ -10,11 +10,11 @@ PHPFlasher.addFactory('noty', (function () {
|
||||
...data.options
|
||||
}
|
||||
|
||||
new Noty(options).show();
|
||||
new PNotify(options);
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
Noty.overrideDefaults(options);
|
||||
PNotify.defaults = options;
|
||||
};
|
||||
|
||||
return exports;
|
||||
@@ -4,9 +4,7 @@ namespace Flasher\Pnotify\Laravel\ServiceProvider\Providers;
|
||||
|
||||
use Flasher\Pnotify\Laravel\FlasherPnotifyServiceProvider;
|
||||
use Flasher\Pnotify\Prime\PnotifyFactory;
|
||||
use Flasher\Pnotify\Prime\PnotifyRenderer;
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Renderer\RendererManager;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
@@ -35,25 +33,14 @@ class Laravel implements ServiceProviderInterface
|
||||
|
||||
public function registerServices()
|
||||
{
|
||||
$this->app->singleton('flasher.factory.pnotify', function (Container $app) {
|
||||
return new PnotifyFactory($app['flasher.event_dispatcher']);
|
||||
$this->app->singleton('flasher.pnotify', function (Container $app) {
|
||||
return new PnotifyFactory($app['flasher.storage_manager']);
|
||||
});
|
||||
|
||||
$this->app->singleton('flasher.renderer.pnotify', function (Container $app) {
|
||||
return new PnotifyRenderer($app['flasher.config']);
|
||||
});
|
||||
|
||||
$this->app->alias('flasher.factory.pnotify', 'Flasher\Pnotify\Prime\PnotifyFactory');
|
||||
$this->app->alias('flasher.renderer.pnotify', 'Flasher\Pnotify\Prime\PnotifyRenderer');
|
||||
$this->app->alias('flasher.pnotify', 'Flasher\Pnotify\Prime\PnotifyFactory');
|
||||
|
||||
$this->app->extend('flasher', function (Flasher $manager, Container $app) {
|
||||
$manager->addFactory($app['flasher.factory.pnotify']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
|
||||
$this->app->extend('flasher.renderer_manager', function (RendererManager $manager, Container $app) {
|
||||
$manager->addDriver($app['flasher.renderer.pnotify']);
|
||||
$manager->addFactory('pnotify', $app['flasher.factory.pnotify']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
|
||||
@@ -6,5 +6,4 @@ use Flasher\Prime\Notification\Notification;
|
||||
|
||||
final class Pnotify extends Notification
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,6 @@ namespace Flasher\Pnotify\Prime;
|
||||
|
||||
use Flasher\Prime\Notification\NotificationBuilder;
|
||||
|
||||
/**
|
||||
* @method Pnotify getNotification()
|
||||
*/
|
||||
final class PnotifyBuilder extends NotificationBuilder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,29 +4,16 @@ namespace Flasher\Pnotify\Prime;
|
||||
|
||||
use Flasher\Prime\Factory\AbstractFactory;
|
||||
|
||||
/**
|
||||
* @mixin PnotifyBuilder
|
||||
*/
|
||||
final class PnotifyFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotification()
|
||||
{
|
||||
return new Pnotify();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotificationBuilder()
|
||||
{
|
||||
return new PnotifyBuilder($this->getStorageManager(), $this->createNotification(), 'pnotify');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'pnotify'));
|
||||
return new PnotifyBuilder($this->getStorageManager(), new Pnotify(), 'pnotify');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Pnotify\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Renderer\HasOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasScriptsInterface;
|
||||
use Flasher\Prime\Renderer\HasStylesInterface;
|
||||
use Flasher\Prime\Renderer\RendererInterface;
|
||||
|
||||
final class PnotifyRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasOptionsInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $scripts;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $styles;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
public function __construct(ConfigInterface $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->scripts = $config->get('adapters.pnotify.scripts', array());
|
||||
$this->styles = $config->get('adapters.pnotify.styles', array());
|
||||
$this->options = $config->get('adapters.pnotify.options', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function render(Envelope $envelope)
|
||||
{
|
||||
$options = $envelope->getOptions();
|
||||
|
||||
$options['text'] = $envelope->getMessage();
|
||||
$options['type'] = $envelope->getType();
|
||||
|
||||
return sprintf("new PNotify(%s);", json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getScripts()
|
||||
{
|
||||
return $this->scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getStyles()
|
||||
{
|
||||
return $this->styles;
|
||||
}
|
||||
|
||||
public function renderOptions()
|
||||
{
|
||||
return sprintf('PNotify.defaults = %s;', json_encode($this->options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'pnotify', 'Flasher\Pnotify\Prime\PnotifyFactory', 'Flasher\Pnotify\Prime\Pnotify'));
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ final class Configuration implements ConfigurationInterface
|
||||
->defaultValue(array(
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/pnotify/3.2.1/pnotify.js',
|
||||
'/bundles/flasherpnotify/flasher-pnotify.js',
|
||||
))
|
||||
->end()
|
||||
->arrayNode('styles')
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
services:
|
||||
flasher.factory.pnotify:
|
||||
flasher.pnotify:
|
||||
parent: 'flasher.abstract_factory'
|
||||
class: Flasher\Pnotify\Prime\PnotifyFactory
|
||||
tags:
|
||||
- { name: 'flasher.factory' }
|
||||
- { name: 'flasher.factory', alias: 'pnotify' }
|
||||
|
||||
flasher.renderer.pnotify:
|
||||
class: Flasher\PFlasher\Prime\PnotifyRenderer
|
||||
arguments:
|
||||
- '@flasher.config'
|
||||
tags:
|
||||
- { name: 'flasher.renderer' }
|
||||
|
||||
Flasher\PFlasher\Prime\PnotifyFactory: '@flasher.factory.pnotify'
|
||||
Flasher\PFlasher\Prime\PnotifyRenderer: '@flasher.renderer.pnotify'
|
||||
Flasher\PFlasher\Prime\PnotifyFactory: '@flasher.pnotify'
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
PHPFlasher.addFactory('noty', (function () {
|
||||
PHPFlasher.addFactory('pnotify', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
@@ -10,11 +10,11 @@ PHPFlasher.addFactory('noty', (function () {
|
||||
...data.options
|
||||
}
|
||||
|
||||
new Noty(options).show();
|
||||
new PNotify(options);
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
Noty.overrideDefaults(options);
|
||||
PNotify.defaults = options;
|
||||
};
|
||||
|
||||
return exports;
|
||||
@@ -1,21 +0,0 @@
|
||||
PHPFlasher.addFactory('noty', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
|
||||
exports.render = function (data) {
|
||||
var options = {
|
||||
text: data.message,
|
||||
type: data.type,
|
||||
...data.options
|
||||
}
|
||||
|
||||
new Noty(options).show();
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
Noty.overrideDefaults(options);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})());
|
||||
+6
-4
@@ -1,4 +1,4 @@
|
||||
PHPFlasher.addFactory('noty', (function () {
|
||||
PHPFlasher.addFactory('sweet_alert', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
@@ -6,15 +6,17 @@ PHPFlasher.addFactory('noty', (function () {
|
||||
exports.render = function (data) {
|
||||
var options = {
|
||||
text: data.message,
|
||||
type: data.type,
|
||||
icon: data.type,
|
||||
...data.options
|
||||
}
|
||||
|
||||
new Noty(options).show();
|
||||
window.SwalToast.fire(options);
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
Noty.overrideDefaults(options);
|
||||
if ("undefined" === typeof window.SwalToast) {
|
||||
window.SwalToast = Swal.mixin(options);
|
||||
}
|
||||
};
|
||||
|
||||
return exports;
|
||||
@@ -3,10 +3,8 @@
|
||||
namespace Flasher\SweetAlert\Laravel\ServiceProvider\Providers;
|
||||
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Renderer\RendererManager;
|
||||
use Flasher\SweetAlert\Laravel\FlasherSweetAlertServiceProvider;
|
||||
use Flasher\SweetAlert\Prime\SweetAlertFactory;
|
||||
use Flasher\SweetAlert\Prime\SweetAlertRenderer;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
@@ -36,24 +34,13 @@ class Laravel implements ServiceProviderInterface
|
||||
public function registerServices()
|
||||
{
|
||||
$this->app->singleton('flasher.factory.sweet_alert', function (Container $app) {
|
||||
return new SweetAlertFactory($app['flasher.event_dispatcher']);
|
||||
return new SweetAlertFactory($app['flasher.storage_manager']);
|
||||
});
|
||||
|
||||
$this->app->singleton('flasher.renderer.sweet_alert', function (Container $app) {
|
||||
return new SweetAlertRenderer($app['flasher.config']);
|
||||
});
|
||||
|
||||
$this->app->alias('flasher.factory.sweet_alert', 'Flasher\SweetAlert\Prime\SweetAlertFactory');
|
||||
$this->app->alias('flasher.renderer.sweet_alert', 'Flasher\SweetAlert\Prime\SweetAlertRenderer');
|
||||
$this->app->alias('flasher.sweet_alert', 'Flasher\SweetAlert\Prime\SweetAlertFactory');
|
||||
|
||||
$this->app->extend('flasher', function (Flasher $manager, Container $app) {
|
||||
$manager->addFactory($app['flasher.factory.sweet_alert']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
|
||||
$this->app->extend('flasher.renderer_manager', function (RendererManager $manager, Container $app) {
|
||||
$manager->addDriver($app['flasher.renderer.sweet_alert']);
|
||||
$manager->addFactory('sweet_alert', $app['flasher.factory.sweet_alert']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
|
||||
@@ -6,5 +6,4 @@ use Flasher\Prime\Notification\Notification;
|
||||
|
||||
final class SweetAlert extends Notification
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -6,5 +6,4 @@ use Flasher\Prime\Notification\NotificationBuilder;
|
||||
|
||||
final class SweetAlertBuilder extends NotificationBuilder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,29 +4,16 @@ namespace Flasher\SweetAlert\Prime;
|
||||
|
||||
use Flasher\Prime\Factory\AbstractFactory;
|
||||
|
||||
/**
|
||||
* @mixin SweetAlertBuilder
|
||||
*/
|
||||
final class SweetAlertFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotification()
|
||||
{
|
||||
return new SweetAlert();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotificationBuilder()
|
||||
{
|
||||
return new SweetAlertBuilder($this->getStorageManager(), $this->createNotification(), 'sweet_alert');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'sweet_alert'));
|
||||
return new SweetAlertBuilder($this->getStorageManager(), new SweetAlert(), 'sweet_alert');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\SweetAlert\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Renderer\HasOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasScriptsInterface;
|
||||
use Flasher\Prime\Renderer\HasStylesInterface;
|
||||
use Flasher\Prime\Renderer\RendererInterface;
|
||||
|
||||
final class SweetAlertRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasOptionsInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $scripts;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $styles;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
public function __construct(ConfigInterface $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->scripts = $config->get('adapters.sweet_alert.scripts', array());
|
||||
$this->styles = $config->get('adapters.sweet_alert.styles', array());
|
||||
$this->options = $config->get('adapters.sweet_alert.options', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function render(Envelope $envelope)
|
||||
{
|
||||
$options = $envelope->getOptions();
|
||||
|
||||
$options['text'] = $envelope->getMessage();
|
||||
$options['icon'] = $envelope->getType();
|
||||
|
||||
if (!empty($options['imageUrl'])) {
|
||||
unset($options['icon']);
|
||||
}
|
||||
|
||||
return sprintf("SwalToast.fire(%s);", json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getScripts()
|
||||
{
|
||||
return $this->scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getStyles()
|
||||
{
|
||||
return $this->styles;
|
||||
}
|
||||
|
||||
public function renderOptions()
|
||||
{
|
||||
return sprintf('var SwalToast = Swal.mixin(%s);', json_encode($this->options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'sweet_alert', 'Flasher\SweetAlert\Prime\SweetAlertFactory', 'Flasher\SweetAlert\Prime\SweetAlert'));
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ final class Configuration implements ConfigurationInterface
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/10.10.2/sweetalert2.min.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/promise-polyfill/8.2.0/polyfill.min.js',
|
||||
'/bundles/flashersweetalert/flasher-sweet-alert.js',
|
||||
))
|
||||
->end()
|
||||
->arrayNode('styles')
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
services:
|
||||
flasher.factory.sweet_alert:
|
||||
parent: 'flasher.factory.abstract'
|
||||
flasher.sweet_alert:
|
||||
parent: 'flasher.abstract_factory'
|
||||
class: Flasher\SweetAlert\Prime\SweetAlertFactory
|
||||
tags:
|
||||
- { name: 'flasher.factory' }
|
||||
- { name: 'flasher.factory', alias: 'sweet_alert' }
|
||||
|
||||
flasher.renderer.sweet_alert:
|
||||
class: Flasher\SweetAlert\Prime\SweetAlertRenderer
|
||||
arguments:
|
||||
- '@flasher.config'
|
||||
tags:
|
||||
- { name: 'flasher.renderer' }
|
||||
|
||||
Flasher\SweetAlert\Prime\SweetAlertFactory: '@flasher.factory.sweet_alert'
|
||||
Flasher\SweetAlert\Prime\SweetAlertRenderer: '@flasher.renderer.sweet_alert'
|
||||
Flasher\SweetAlert\Prime\SweetAlertFactory: '@flasher.sweet_alert'
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
PHPFlasher.addFactory('noty', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
|
||||
exports.render = function (data) {
|
||||
var options = {
|
||||
text: data.message,
|
||||
type: data.type,
|
||||
...data.options
|
||||
}
|
||||
|
||||
new Noty(options).show();
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
Noty.overrideDefaults(options);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})());
|
||||
+6
-4
@@ -1,4 +1,4 @@
|
||||
PHPFlasher.addFactory('noty', (function () {
|
||||
PHPFlasher.addFactory('sweet_alert', (function () {
|
||||
'use strict';
|
||||
|
||||
var exports = {};
|
||||
@@ -6,15 +6,17 @@ PHPFlasher.addFactory('noty', (function () {
|
||||
exports.render = function (data) {
|
||||
var options = {
|
||||
text: data.message,
|
||||
type: data.type,
|
||||
icon: data.type,
|
||||
...data.options
|
||||
}
|
||||
|
||||
new Noty(options).show();
|
||||
window.SwalToast.fire(options);
|
||||
};
|
||||
|
||||
exports.renderOptions = function (options) {
|
||||
Noty.overrideDefaults(options);
|
||||
if ("undefined" === typeof window.SwalToast) {
|
||||
window.SwalToast = Swal.mixin(options);
|
||||
}
|
||||
};
|
||||
|
||||
return exports;
|
||||
@@ -25,7 +25,7 @@ final class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->scalarNode('default')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue('toastr')
|
||||
->defaultValue('notyf')
|
||||
->end()
|
||||
->arrayNode('scripts')
|
||||
->prototype('scalar')->end()
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
namespace Flasher\Toastr\Laravel\ServiceProvider\Providers;
|
||||
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Renderer\RendererManager;
|
||||
use Flasher\Toastr\Laravel\FlasherToastrServiceProvider;
|
||||
use Flasher\Toastr\Prime\ToastrFactory;
|
||||
use Flasher\Toastr\Prime\ToastrRenderer;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
@@ -35,28 +33,17 @@ class Laravel implements ServiceProviderInterface
|
||||
|
||||
public function registerToastrServices()
|
||||
{
|
||||
$this->app->singleton('flasher.factory.toastr', function (Container $app) {
|
||||
return new ToastrFactory($app['flasher.event_dispatcher']);
|
||||
$this->app->singleton('flasher.toastr', function (Container $app) {
|
||||
return new ToastrFactory($app['flasher.storage_manager']);
|
||||
});
|
||||
|
||||
$this->app->singleton('flasher.renderer.toastr', function (Container $app) {
|
||||
return new ToastrRenderer($app['flasher.config']);
|
||||
});
|
||||
|
||||
$this->app->alias('flasher.factory.toastr', 'Flasher\Toastr\Prime\ToastrFactory');
|
||||
$this->app->alias('flasher.renderer.toastr', 'Flasher\Toastr\Prime\ToastrRenderer');
|
||||
$this->app->alias('flasher.toastr', 'Flasher\Toastr\Prime\ToastrFactory');
|
||||
|
||||
$this->app->extend('flasher', function (Flasher $flasher, Container $app) {
|
||||
$flasher->addFactory($app['flasher.factory.toastr']);
|
||||
$flasher->addFactory('toastr', $app['flasher.toastr']);
|
||||
|
||||
return $flasher;
|
||||
});
|
||||
|
||||
$this->app->extend('flasher.renderer_manager', function (RendererManager $manager, Container $app) {
|
||||
$manager->addDriver($app['flasher.renderer.toastr']);
|
||||
|
||||
return $manager;
|
||||
});
|
||||
}
|
||||
|
||||
public function mergeConfigFromToastr()
|
||||
|
||||
@@ -18,7 +18,7 @@ final class FlasherToastrExtension extends Extension implements PrependExtension
|
||||
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();
|
||||
$this->processConfiguration($configuration, $configs);
|
||||
|
||||
Reference in New Issue
Block a user