add Desktop stamp and callback specification and events

This commit is contained in:
Khoubza Younes
2021-09-28 16:39:38 +01:00
parent f879237ab5
commit 3f845a4137
31 changed files with 730 additions and 173 deletions
-4
View File
@@ -1,7 +1,3 @@
<?php
namespace PHPSTORM_META;
use Flasher\Prime\Notification\NotificationInterface;
expectedArguments(\console(), 1, 'success', 'error', 'info', 'warning');
@@ -31,7 +31,7 @@ final class FlasherCliServiceProvider extends ServiceProvider
public function provides()
{
return array(
'flasher.console',
'flasher.cli',
);
}
+1 -1
View File
@@ -34,7 +34,7 @@
# Why use PHP Flasher ?
The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __console.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__
The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __toastr.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__
and its highly extendable so you can add your custom notifications.
This library is designed, so you can take full control when creating you notifications :
@@ -30,45 +30,45 @@ class Laravel implements ServiceProviderInterface
public function boot(FlasherCliServiceProvider $provider)
{
$provider->publishes(array(
flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher_console.php'),
flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher_cli.php'),
), 'flasher-config');
}
public function register(FlasherCliServiceProvider $provider)
{
$provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher_console');
$provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher_cli');
$this->registerServices();
}
public function registerServices()
{
$this->app->singleton('flasher.console.notify_send', function (Container $app) {
$options = $app['config']->get('flasher_console.notify_send', array());
$this->app->singleton('flasher.cli.notify_send', function (Container $app) {
$options = $app['config']->get('flasher_cli.notify_send', array());
$options['icons'] = array_replace_recursive($app['config']->get('flasher_console.icons', array()), $options['icons']);
$options['title'] = $app['config']->get('flasher_console.title', null);
$options['mute'] = $app['config']->get('flasher_console.mute', true);
$options['icons'] = array_replace_recursive($app['config']->get('flasher_cli.icons', array()), $options['icons']);
$options['title'] = $app['config']->get('flasher_cli.title', null);
$options['mute'] = $app['config']->get('flasher_cli.mute', true);
return new NotifySendNotifier($options);
});
$this->app->singleton('flasher.console', function (Container $app) {
$console = new FlasherCli();
$this->app->singleton('flasher.cli', function (Container $app) {
$cli = new FlasherCli();
$console->addNotifier($app['flasher.console.notify_send']);
$cli->addNotifier($app['flasher.cli.notify_send']);
return $console;
return $cli;
});
$this->app->extend('flasher.event_dispatcher', function (EventDispatcher $eventDispatcher, Container $app) {
$eventDispatcher->addSubscriber(new RenderListener($app['flasher.console']));
$eventDispatcher->addSubscriber(new RenderListener($app['flasher.cli']));
return $eventDispatcher;
});
$this->app->alias('flasher.console', 'Flasher\Console\Prime\FlasherCli');
$this->app->alias('flasher.cli', 'Flasher\Cli\Prime\FlasherCli');
}
}
@@ -16,7 +16,7 @@ final class Laravel4 extends Laravel
{
$provider->package(
'php-flasher/flasher-cli-laravel',
'flasher_console',
'flasher_cli',
flasher_path(__DIR__ . '/../../Resources')
);
}
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "php-flasher/flasher-cli-laravel",
"description": "PHP Flasher Laravel adapter for Console",
"description": "PHP Flasher Laravel adapter for Cli",
"type": "library",
"keywords": [
"yoeunes",
@@ -13,7 +13,7 @@
"messages",
"alerts",
"pnotify",
"console ",
"cli ",
"bundle",
"flex"
],
@@ -38,7 +38,7 @@
},
"autoload": {
"psr-4": {
"Flasher\\Console\\Laravel\\": ""
"Flasher\\Cli\\Laravel\\": ""
},
"exclude-from-classmap": [
"/Tests/"
@@ -46,13 +46,13 @@
},
"autoload-dev": {
"psr-4": {
"Flasher\\Console\\Laravel\\Tests\\": "Tests/"
"Flasher\\Cli\\Laravel\\Tests\\": "Tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Flasher\\Console\\Laravel\\FlasherCliServiceProvider"
"Flasher\\Cli\\Laravel\\FlasherCliServiceProvider"
]
}
},
+15 -7
View File
@@ -2,11 +2,13 @@
namespace Flasher\Cli\Prime\EventListener;
use Flasher\Prime\EventDispatcher\Event\PersistEvent;
use Flasher\Cli\Prime\Stamp\DesktopStamp;
use Flasher\Prime\Envelope;
use Flasher\Prime\EventDispatcher\Event\PostPersistEvent;
use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface;
use Flasher\Prime\FlasherInterface;
class RenderListener implements EventSubscriberInterface
final class RenderListener implements EventSubscriberInterface
{
private $flasher;
@@ -16,22 +18,28 @@ class RenderListener implements EventSubscriberInterface
}
/**
* @param PersistEvent $event
* @param PostPersistEvent $event
*/
public function __invoke($event)
{
return;
if (PHP_SAPI !== 'cli') {
return;
}
$envelopes = $event->getEnvelopes();
$callback = function(Envelope $envelope) {
$stamp = $envelope->get('Flasher\Cli\Prime\Stamp\DesktopStamp');
if (!$stamp instanceof DesktopStamp) {
return false;
}
$this->FlasherCli->render($envelopes);
return $stamp->isRenderImmediately();
};
$this->flasher->render(array('filter' => $callback), 'cli');
}
public static function getSubscribedEvents()
{
return 'Flasher\Prime\EventDispatcher\Event\PersistEvent';
return 'Flasher\Prime\EventDispatcher\Event\PostPersistEvent';
}
}
@@ -0,0 +1,48 @@
<?php
namespace Flasher\Cli\Prime\EventListener;
use Flasher\Cli\Prime\Stamp\DesktopStamp;
use Flasher\Prime\Envelope;
use Flasher\Prime\EventDispatcher\Event\PersistEvent;
use Flasher\Prime\EventDispatcher\Event\UpdateEvent;
use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface;
final class StampsListener implements EventSubscriberInterface
{
private $renderAll;
private $renderImmediately;
public function __construct($renderAll, $renderImmediately)
{
$this->renderAll = $renderAll;
$this->renderImmediately = $renderImmediately;
}
/**
* @param PersistEvent|UpdateEvent $event
*/
public function __invoke($event)
{
if (PHP_SAPI !== 'cli') {
return;
}
foreach ($event->getEnvelopes() as $envelope) {
$this->attachStamps($envelope);
}
}
public static function getSubscribedEvents()
{
return 'Flasher\Prime\EventDispatcher\Event\PersistEvent';
}
private function attachStamps(Envelope $envelope)
{
$stamp = $envelope->get('Flasher\Cli\Prime\Stamp\DesktopStamp');
if (null === $stamp && true === $this->renderAll) {
$envelope->withStamp(new DesktopStamp($this->renderImmediately));
}
}
}
-20
View File
@@ -2,15 +2,8 @@
namespace Flasher\Cli\Prime\Presenter;
use Flasher\Cli\Prime\Notifier\GrowlNotifyNotifier;
use Flasher\Cli\Prime\Notifier\KDialogNotifier;
use Flasher\Cli\Prime\Notifier\NotifierInterface;
use Flasher\Cli\Prime\Notifier\NotifuNotifier;
use Flasher\Cli\Prime\Notifier\NotifySendNotifier;
use Flasher\Cli\Prime\Notifier\NullNotifier;
use Flasher\Cli\Prime\Notifier\SnoreToastNotifier;
use Flasher\Cli\Prime\Notifier\TerminalNotifierNotifier;
use Flasher\Cli\Prime\Notifier\ToasterNotifier;
use Flasher\Prime\Response\Presenter\PresenterInterface;
use Flasher\Prime\Response\Response;
@@ -21,19 +14,6 @@ final class CliPresenter implements PresenterInterface
*/
private $notifiers = array();
public function __construct()
{
$this->notifiers = array(
new GrowlNotifyNotifier(),
new NotifuNotifier(),
new TerminalNotifierNotifier(),
new SnoreToastNotifier(),
new ToasterNotifier(),
new NotifySendNotifier(),
new KDialogNotifier(),
);
}
public function render(Response $response)
{
$notifier = $this->createNotifier();
+1 -1
View File
@@ -34,7 +34,7 @@
# Why use PHP Flasher ?
The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __console.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__
The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __cli.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__
and its highly extendable so you can add your custom notifications.
This library is designed, so you can take full control when creating you notifications :
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace Flasher\Cli\Prime\Stamp;
use Flasher\Prime\Stamp\StampInterface;
final class DesktopStamp implements StampInterface
{
/** @var bool */
private $renderImmediately;
public function __construct($renderImmediately = true)
{
$this->renderImmediately = $renderImmediately;
}
/**
* @return bool
*/
public function isRenderImmediately()
{
return $this->renderImmediately;
}
}
+6 -4
View File
@@ -1,6 +1,6 @@
{
"name": "php-flasher/flasher-cli",
"description": "PHP Flasher adapter for Console",
"description": "PHP Flasher adapter for Cli Console Terminal",
"type": "library",
"keywords": [
"notify",
@@ -12,7 +12,9 @@
"messages",
"alerts",
"pnotify",
"console "
"console",
"Cli",
"Terminal"
],
"homepage": "https://php-flasher.github.io/",
"authors": [
@@ -33,7 +35,7 @@
},
"autoload": {
"psr-4": {
"Flasher\\Console\\Prime\\": ""
"Flasher\\Cli\\Prime\\": ""
},
"exclude-from-classmap": [
"/Tests/"
@@ -41,7 +43,7 @@
},
"autoload-dev": {
"psr-4": {
"Flasher\\Console\\Prime\\Tests\\": "Tests/"
"Flasher\\Cli\\Prime\\Tests\\": "Tests/"
}
},
"config": {
@@ -2,7 +2,6 @@
namespace Flasher\Cli\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\Flasher;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -11,15 +10,14 @@ final class NotifierCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// if (!$container->has('flasher.console')) {
// return;
// }
//
// /** @var Flasher $manager */
// $manager = $container->findDefinition('flasher.console');
//
// foreach ($container->findTaggedServiceIds('flasher.console_notifier') as $id => $tags) {
// $manager->addMethodCall('addNotifier', array(new Reference($id)));
// }
if (!$container->has('flasher.presenter.cli')) {
return;
}
$presenter = $container->findDefinition('flasher.presenter.cli');
foreach ($container->findTaggedServiceIds('flasher.cli_notifier') as $id => $tags) {
$presenter->addMethodCall('addNotifier', array(new Reference($id)));
}
}
}
@@ -2,6 +2,7 @@
namespace Flasher\Cli\Symfony\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -9,22 +10,22 @@ final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('flasher_console');
if (\method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('flasher_console');
}
$treeBuilder = new TreeBuilder('flasher_cli');
$rootNode = $this->getRootNode($treeBuilder, 'flasher_cli');
$rootNode
->children()
->booleanNode('render_all')
->defaultValue(false)
->end()
->booleanNode('render_immediately')
->defaultValue(true)
->end()
->scalarNode('title')
->defaultValue('PHP Flasher')
->end()
->booleanNode('mute')
->defaultValue(false)
->defaultValue(true)
->end()
->arrayNode('filter_criteria')
->prototype('variable')->end()
@@ -34,31 +35,299 @@ final class Configuration implements ConfigurationInterface
->prototype('variable')->end()
->defaultValue(array())
->end()
->arrayNode('notify_send')
->addDefaultsIfNotSet()
->children()
->scalarNode('service')
->defaultValue('flasher.console.notify_send')
->end()
->scalarNode('binary')
->defaultValue('notify-send')
->cannotBeEmpty()
->end()
->integerNode('expire_time')
->defaultValue(0)
->end()
->booleanNode('enabled')
->defaultValue(true)
->end()
->arrayNode('icons')
->prototype('variable')->end()
->defaultValue(array())
->end()
->end()
->end()
->append($this->addNotifiersConfig())
->end()
;
return $treeBuilder;
}
private function addNotifiersConfig()
{
$treeBuilder = new TreeBuilder('notifiers');
$rootNode = $this->getRootNode($treeBuilder, 'notifiers');
$rootNode
->addDefaultsIfNotSet()
->children()
->append($this->addGrowlNotifyNotifier())
->append($this->addKDialogNotifier())
->append($this->addNotifuNotifier())
->append($this->addNotifySendNotifier())
->append($this->addSnoreToastNotifier())
->append($this->addTerminalNotifierNotifier())
->append($this->addToasterNotifier())
->end();
return $rootNode;
}
/**
* @return ArrayNodeDefinition
*/
private function addGrowlNotifyNotifier()
{
$treeBuilder = new TreeBuilder('growl_notify');
$rootNode = $this->getRootNode($treeBuilder, 'growl_notify');
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('service')->defaultValue('flasher.cli.growl_notify')->end()
->scalarNode('binary')->defaultValue('notify-send')->end()
->arrayNode('binary_paths')
->beforeNormalization()
->ifString()
->then(function($v) { return array($v); })
->end()
->prototype('scalar')->end()
->end()
->scalarNode('title')->defaultValue(null)->end()
->booleanNode('mute')->defaultValue(true)->end()
->arrayNode('icons')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('sounds')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->end()
;
return $rootNode;
}
/**
* @return ArrayNodeDefinition
*/
private function addKDialogNotifier()
{
$treeBuilder = new TreeBuilder('kdialog_notifier');
$rootNode = $this->getRootNode($treeBuilder, 'kdialog_notifier');
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('service')->defaultValue('flasher.cli.kdialog_notifier')->end()
->scalarNode('binary')->defaultValue('notify-send')->end()
->arrayNode('binary_paths')
->beforeNormalization()
->ifString()
->then(function($v) { return array($v); })
->end()
->prototype('scalar')->end()
->end()
->scalarNode('title')->defaultValue(null)->end()
->booleanNode('mute')->defaultValue(true)->end()
->arrayNode('icons')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('sounds')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->end()
;
return $rootNode;
}
/**
* @return ArrayNodeDefinition
*/
private function addNotifuNotifier()
{
$treeBuilder = new TreeBuilder('notifu_notifier');
$rootNode = $this->getRootNode($treeBuilder, 'notifu_notifier');
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('service')->defaultValue('flasher.cli.notifu_notifier')->end()
->scalarNode('binary')->defaultValue('notify-send')->end()
->arrayNode('binary_paths')
->beforeNormalization()
->ifString()
->then(function($v) { return array($v); })
->end()
->prototype('scalar')->end()
->end()
->scalarNode('title')->defaultValue(null)->end()
->booleanNode('mute')->defaultValue(true)->end()
->arrayNode('icons')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('sounds')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->end()
;
return $rootNode;
}
/**
* @return ArrayNodeDefinition
*/
private function addNotifySendNotifier()
{
$treeBuilder = new TreeBuilder('notify_send');
$rootNode = $this->getRootNode($treeBuilder, 'notify_send');
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('service')->defaultValue('flasher.cli.notify_send')->end()
->scalarNode('binary')->defaultValue('notify-send')->end()
->arrayNode('binary_paths')
->beforeNormalization()
->ifString()
->then(function($v) { return array($v); })
->end()
->prototype('scalar')->end()
->end()
->scalarNode('title')->defaultValue(null)->end()
->booleanNode('mute')->defaultValue(true)->end()
->arrayNode('icons')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('sounds')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->end()
;
return $rootNode;
}
/**
* @return ArrayNodeDefinition
*/
private function addSnoreToastNotifier()
{
$treeBuilder = new TreeBuilder('snore_toast_notifier');
$rootNode = $this->getRootNode($treeBuilder, 'snore_toast_notifier');
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('service')->defaultValue('flasher.cli.snore_toast_notifier')->end()
->scalarNode('binary')->defaultValue('notify-send')->end()
->arrayNode('binary_paths')
->beforeNormalization()
->ifString()
->then(function($v) { return array($v); })
->end()
->prototype('scalar')->end()
->end()
->scalarNode('title')->defaultValue(null)->end()
->booleanNode('mute')->defaultValue(true)->end()
->arrayNode('icons')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('sounds')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->end()
;
return $rootNode;
}
/**
* @return ArrayNodeDefinition
*/
private function addTerminalNotifierNotifier()
{
$treeBuilder = new TreeBuilder('terminal_notifier_notifier');
$rootNode = $this->getRootNode($treeBuilder, 'terminal_notifier_notifier');
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('service')->defaultValue('flasher.cli.terminal_notifier_notifier')->end()
->scalarNode('binary')->defaultValue('notify-send')->end()
->arrayNode('binary_paths')
->beforeNormalization()
->ifString()
->then(function($v) { return array($v); })
->end()
->prototype('scalar')->end()
->end()
->scalarNode('title')->defaultValue(null)->end()
->booleanNode('mute')->defaultValue(true)->end()
->arrayNode('icons')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('sounds')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->end()
;
return $rootNode;
}
/**
* @return ArrayNodeDefinition
*/
private function addToasterNotifier()
{
$treeBuilder = new TreeBuilder('toaster_send');
$rootNode = $this->getRootNode($treeBuilder, 'toaster_send');
$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('service')->defaultValue('flasher.cli.toaster_send')->end()
->scalarNode('binary')->defaultValue('notify-send')->end()
->arrayNode('binary_paths')
->beforeNormalization()
->ifString()
->then(function($v) { return array($v); })
->end()
->prototype('scalar')->end()
->end()
->scalarNode('title')->defaultValue(null)->end()
->booleanNode('mute')->defaultValue(true)->end()
->arrayNode('icons')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('sounds')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->end()
;
return $rootNode;
}
private function getRootNode(TreeBuilder $treeBuilder, $name)
{
// BC layer for symfony/config 4.1 and older
if (\method_exists($treeBuilder, 'getRootNode')) {
return $treeBuilder->getRootNode();
}
return $treeBuilder->root($name);
}
}
@@ -17,31 +17,44 @@ final class FlasherCliExtension extends Extension
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
dd($config);
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('config.php');
// $this->registerFlasherCliConfigration($config, $container);
// $this->registerNotifySendConfigration($config, $container);
$container
->findDefinition('flasher.event_listener.cli_stamps_listener')
->replaceArgument(0, $config['render_all'])
->replaceArgument(1, $config['render_immediately']);
$this->registerNotifiersConfiguration($container, $config);
}
private function registerFlasherCliConfigration(array $config, ContainerBuilder $container)
private function registerNotifiersConfiguration(ContainerBuilder $container, array $config)
{
$container
->findDefinition('flasher.console')
->replaceArgument(2, $config['filter_criteria']);
$this->registerNotifier($container, $config, 'growl_notify');
$this->registerNotifier($container, $config, 'kdialog_notifier');
$this->registerNotifier($container, $config, 'notifu_notifier');
$this->registerNotifier($container, $config, 'notify_send');
$this->registerNotifier($container, $config, 'snore_toast_notifier');
$this->registerNotifier($container, $config, 'terminal_notifier_notifier');
$this->registerNotifier($container, $config, 'toaster_send');
}
private function registerNotifySendConfigration(array $config, ContainerBuilder $container)
private function registerNotifier(ContainerBuilder $container, array $config, $notifier)
{
$notifySendConfig = $config['notify_send'];
$notifySendConfig['icons'] = array_replace_recursive($config['icons'], $notifySendConfig['icons']);
$notifySendConfig['title'] = $config['title'];
$notifySendConfig['mute'] = $config['mute'];
$container
->findDefinition('flasher.console.notify_send')
->replaceArgument(0, $notifySendConfig);
->findDefinition("flasher.cli.$notifier")
->replaceArgument(0, $this->createConfigFor($config, $notifier));
}
private function createConfigFor(array $config, $notifier)
{
$options = $config[$notifier];
$options['title'] = $config['title'];
$options['mute'] = $config['mute'];
$options['icons'] = array_replace_recursive($config['icons'], $options['icons']);
return $options;
}
}
@@ -2,13 +2,22 @@
namespace Flasher\Cli\Symfony;
use Flasher\Cli\Prime\Stamp\DesktopStamp;
use Flasher\Cli\Symfony\DependencyInjection\Compiler\NotifierCompilerPass;
use Flasher\Prime\Notification\NotificationBuilder;
use Flasher\Symfony\Bridge\FlasherBundle;
use Flasher\Cli\Symfony\DependencyInjection\FlasherCliExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class FlasherCliSymfonyBundle extends FlasherBundle
{
public function boot()
{
NotificationBuilder::macro('desktop', function ($renderImmediately = true) {
return $this->withStamp(new DesktopStamp($renderImmediately));
});
}
protected function flasherBuild(ContainerBuilder $container)
{
$container->addCompilerPass(new NotifierCompilerPass());
+1 -1
View File
@@ -34,7 +34,7 @@
# Why use PHP Flasher ?
The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __console.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__
The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __toastr.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__
and its highly extendable so you can add your custom notifications.
This library is designed, so you can take full control when creating you notifications :
+44 -3
View File
@@ -1,9 +1,9 @@
<?php
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Flasher\Symfony\Bridge\Bridge;
use Symfony\Component\DependencyInjection\Reference;
if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) {
$definition = new ChildDefinition('flasher.notification_factory');
@@ -22,9 +22,50 @@ $container
->addTag('flasher.presenter', array('alias' => 'cli'));
$container
->register('flasher.console.notify_send', 'Flasher\Console\Prime\Notifier\NotifySendNotifier')
->register('flasher.event_listener.cli_stamps_listener', 'Flasher\Cli\Prime\EventListener\StampsListener')
->addArgument(false)
->addArgument(true)
->addTag('flasher.event_subscriber');
$container
->register('flasher.event_listener.cli_render_listener', 'Flasher\Cli\Prime\EventListener\RenderListener')
->addArgument(new Reference('flasher'))
->addTag('flasher.event_subscriber', array('priority' => -256));
$container
->register('flasher.cli.growl_notify', 'Flasher\Cli\Prime\Notifier\GrowlNotifyNotifier')
->addArgument(array())
->addTag('flasher.console_notifier');
->addTag('flasher.cli_notifier');
$container
->register('flasher.cli.kdialog_notifier', 'Flasher\Cli\Prime\Notifier\KDialogNotifier')
->addArgument(array())
->addTag('flasher.cli_notifier');
$container
->register('flasher.cli.notifu_notifier', 'Flasher\Cli\Prime\Notifier\NotifuNotifier')
->addArgument(array())
->addTag('flasher.cli_notifier');
$container
->register('flasher.cli.notify_send', 'Flasher\Cli\Prime\Notifier\NotifySendNotifier')
->addArgument(array())
->addTag('flasher.cli_notifier');
$container
->register('flasher.cli.snore_toast_notifier', 'Flasher\Cli\Prime\Notifier\SnoreToastNotifier')
->addArgument(array())
->addTag('flasher.cli_notifier');
$container
->register('flasher.cli.terminal_notifier_notifier', 'Flasher\Cli\Prime\Notifier\TerminalNotifierNotifier')
->addArgument(array())
->addTag('flasher.cli_notifier');
$container
->register('flasher.cli.toaster_send', 'Flasher\Cli\Prime\Notifier\ToasterNotifier')
->addArgument(array())
->addTag('flasher.cli_notifier');
if (Bridge::canLoadAliases()) {
$container->setAlias('Flasher\Cli\Prime\CliNotificationFactory', 'flasher.cli');
+6 -4
View File
@@ -1,7 +1,7 @@
{
"name": "php-flasher/flasher-cli-symfony",
"type": "symfony-bundle",
"description": "PHP Flasher Symfony adapter for Console",
"description": "PHP Flasher Symfony adapter for Cli Console Terminal",
"keywords": [
"yoeunes",
"notify",
@@ -13,7 +13,9 @@
"messages",
"alerts",
"pnotify",
"console ",
"console",
"cli",
"terminal",
"bundle",
"flex"
],
@@ -37,7 +39,7 @@
},
"autoload": {
"psr-4": {
"Flasher\\Console\\Symfony\\": ""
"Flasher\\Cli\\Symfony\\": ""
},
"exclude-from-classmap": [
"/Tests/"
@@ -45,7 +47,7 @@
},
"autoload-dev": {
"psr-4": {
"Flasher\\Console\\Symfony\\Tests\\": "Tests/"
"Flasher\\Cli\\Symfony\\Tests\\": "Tests/"
}
},
"config": {
+28
View File
@@ -67,6 +67,34 @@ final class Envelope implements NotificationInterface
return $this;
}
/**
* @param array|StampInterface $stamps
*
* @return Envelope A new Envelope instance without any stamps of the given class
*/
public function without($stamps)
{
$stamps = is_array($stamps) ? $stamps : func_get_args();
foreach ($stamps as $stamp) {
$this->withoutStamp($stamp);
}
return $this;
}
/**
* @param string|StampInterface $type
*/
public function withoutStamp($type)
{
$type = $type instanceof StampInterface ? get_class($type) : $type;
unset($this->stamps[$type]);
return $this;
}
/**
* @param string $stampFqcn
*
@@ -0,0 +1,29 @@
<?php
namespace Flasher\Prime\EventDispatcher\Event;
use Flasher\Prime\Envelope;
final class PostPersistEvent
{
/**
* @var Envelope[]
*/
private $envelopes;
/**
* @param Envelope[] $envelopes
*/
public function __construct(array $envelopes)
{
$this->envelopes = $envelopes;
}
/**
* @return Envelope[]
*/
public function getEnvelopes()
{
return $this->envelopes;
}
}
@@ -0,0 +1,43 @@
<?php
namespace Flasher\Prime\EventDispatcher\Event;
use Flasher\Prime\Envelope;
final class PostRemoveEvent
{
/**
* @var Envelope[]
*/
private $envelopesToRemove = array();
/**
* @var Envelope[]
*/
private $envelopesToKeep = array();
/**
* @param Envelope[] $envelopesToRemove
*/
public function __construct(array $envelopesToRemove, array $envelopesToKeep)
{
$this->envelopesToRemove = $envelopesToRemove;
$this->envelopesToKeep = $envelopesToKeep;
}
/**
* @return Envelope[]
*/
public function getEnvelopesToRemove()
{
return $this->envelopesToRemove;
}
/**
* @return Envelope[]
*/
public function getEnvelopesToKeep()
{
return $this->envelopesToKeep;
}
}
@@ -0,0 +1,29 @@
<?php
namespace Flasher\Prime\EventDispatcher\Event;
use Flasher\Prime\Envelope;
final class PostUpdateEvent
{
/**
* @var Envelope[]
*/
private $envelopes;
/**
* @param Envelope[] $envelopes
*/
public function __construct(array $envelopes)
{
$this->envelopes = $envelopes;
}
/**
* @return Envelope[]
*/
public function getEnvelopes()
{
return $this->envelopes;
}
}
+13
View File
@@ -2,6 +2,7 @@
namespace Flasher\Prime\Filter;
use Flasher\Prime\Filter\Specification\CallbackSpecification;
use Flasher\Prime\Filter\Specification\DelaySpecification;
use Flasher\Prime\Filter\Specification\HopsSpecification;
use Flasher\Prime\Filter\Specification\PrioritySpecification;
@@ -34,6 +35,7 @@ final class CriteriaBuilder
$this->buildLimit();
$this->buildOrder();
$this->buildStamps();
$this->buildFilter();
return $this->filterBuilder;
}
@@ -156,4 +158,15 @@ final class CriteriaBuilder
$this->filterBuilder->andWhere(new StampsSpecification($this->criteria['stamps'], $strategy));
}
public function buildFilter()
{
if (!isset($this->criteria['filter'])) {
return;
}
foreach ((array) $this->criteria['filter'] as $callback) {
$this->filterBuilder->andWhere(new CallbackSpecification($this->filterBuilder, $callback));
}
}
}
+33 -33
View File
@@ -28,39 +28,6 @@ final class FilterBuilder
*/
private $maxResults;
/**
* @param array<string, string> $orderings
*
* @return self
*/
public function orderBy(array $orderings)
{
$this->orderings = array_map(static function ($ordering) {
return strtoupper($ordering) === FilterBuilder::ASC ? FilterBuilder::ASC : FilterBuilder::DESC;
}, $orderings);
return $this;
}
/**
* @return array<string, string>
*/
public function getOrderings()
{
return $this->orderings;
}
/**
* @return $this
*/
public function withCriteria(array $criteria)
{
$criteriaBuilder = new CriteriaBuilder($this, $criteria);
$criteriaBuilder->build();
return $this;
}
/**
* @param Envelope[] $envelopes
*
@@ -112,6 +79,39 @@ final class FilterBuilder
return $envelopes;
}
/**
* @return $this
*/
public function withCriteria(array $criteria)
{
$criteriaBuilder = new CriteriaBuilder($this, $criteria);
$criteriaBuilder->build();
return $this;
}
/**
* @param array<string, string> $orderings
*
* @return self
*/
public function orderBy(array $orderings)
{
$this->orderings = array_map(static function ($ordering) {
return strtoupper($ordering) === FilterBuilder::ASC ? FilterBuilder::ASC : FilterBuilder::DESC;
}, $orderings);
return $this;
}
/**
* @return array<string, string>
*/
public function getOrderings()
{
return $this->orderings;
}
/**
* @return SpecificationInterface
*/
@@ -0,0 +1,26 @@
<?php
namespace Flasher\Prime\Filter\Specification;
use Flasher\Prime\Envelope;
use Flasher\Prime\Filter\FilterBuilder;
final class CallbackSpecification implements SpecificationInterface
{
private $filterBuilder;
private $callback;
/**
* @param callable $callback
*/
public function __construct(FilterBuilder $filterBuilder, $callback)
{
$this->filterBuilder = $filterBuilder;
$this->callback = $callback;
}
public function isSatisfiedBy(Envelope $envelope)
{
return call_user_func($this->callback, $envelope, $this->filterBuilder);
}
}
@@ -10,9 +10,6 @@ use Flasher\Prime\Stamp\PriorityStamp;
use Flasher\Prime\Stamp\StampInterface;
use Flasher\Prime\Storage\StorageManagerInterface;
/**
* @method self livewire(array $context = array())
*/
class NotificationBuilder implements NotificationBuilderInterface
{
/**
@@ -5,6 +5,10 @@ namespace Flasher\Prime\Notification;
use Flasher\Prime\Envelope;
use Flasher\Prime\Stamp\StampInterface;
/**
* @method self livewire(array $context = array())
* @method self desktop(bool $renderImmediately = true)
*/
interface NotificationBuilderInterface
{
/**
-7
View File
@@ -1,7 +0,0 @@
<?php
namespace Flasher\Prime\Stamp;
final class DesktopStamp implements StampInterface
{
}
-7
View File
@@ -1,7 +0,0 @@
<?php
namespace Flasher\Prime\Stamp;
final class QueueStamp implements StampInterface
{
}
+12
View File
@@ -3,6 +3,9 @@
namespace Flasher\Prime\Storage;
use Flasher\Prime\EventDispatcher\Event\PersistEvent;
use Flasher\Prime\EventDispatcher\Event\PostPersistEvent;
use Flasher\Prime\EventDispatcher\Event\PostRemoveEvent;
use Flasher\Prime\EventDispatcher\Event\PostUpdateEvent;
use Flasher\Prime\EventDispatcher\Event\RemoveEvent;
use Flasher\Prime\EventDispatcher\Event\UpdateEvent;
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
@@ -38,6 +41,9 @@ final class StorageManager implements StorageManagerInterface
$this->eventDispatcher->dispatch($event);
$this->storage->add($event->getEnvelopes());
$event = new PostPersistEvent($event->getEnvelopes());
$this->eventDispatcher->dispatch($event);
}
public function update($envelopes)
@@ -48,6 +54,9 @@ final class StorageManager implements StorageManagerInterface
$this->eventDispatcher->dispatch($event);
$this->storage->update($event->getEnvelopes());
$event = new PostUpdateEvent($event->getEnvelopes());
$this->eventDispatcher->dispatch($event);
}
public function remove($envelopes)
@@ -59,6 +68,9 @@ final class StorageManager implements StorageManagerInterface
$this->storage->update($event->getEnvelopesToKeep());
$this->storage->remove($event->getEnvelopesToRemove());
$event = new PostRemoveEvent($event->getEnvelopesToRemove(), $event->getEnvelopesToKeep());
$this->eventDispatcher->dispatch($event);
}
public function clear()