diff --git a/composer.json b/composer.json
old mode 100644
new mode 100755
index fac4e7c3..24f46728
--- a/composer.json
+++ b/composer.json
@@ -13,12 +13,7 @@
],
"require": {
"php": ">=5.3",
- "ext-json": "*",
- "illuminate/support": "4.0.*"
- },
- "require-dev": {
- "phpunit/phpunit": "4.8.36",
- "orchestra/testbench": "^2.0|^3.0|^4.0|^5.0|^6.0"
+ "ext-json": "*"
},
"autoload": {
"psr-4": {
@@ -28,10 +23,5 @@
"src/Prime/helpers.php"
]
},
- "minimum-stability": "dev",
- "config": {
- "platform": {
- "php": "5.4"
- }
- }
+ "minimum-stability": "dev"
}
diff --git a/src/Laravel/Middleware/SessionMiddleware.php b/src/Laravel/Middleware/SessionMiddleware.php
old mode 100644
new mode 100755
index 38bc4c55..82121e2c
--- a/src/Laravel/Middleware/SessionMiddleware.php
+++ b/src/Laravel/Middleware/SessionMiddleware.php
@@ -5,7 +5,7 @@ namespace Flasher\Laravel\Middleware;
use Closure;
use Flasher\Prime\Config\ConfigInterface;
use Flasher\Prime\FlasherInterface;
-use Flasher\Prime\Renderer\RendererInterface;
+use Flasher\Prime\Response\ResponseManagerInterface;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -22,16 +22,16 @@ final class SessionMiddleware
private $flasher;
/**
- * @var RendererInterface
+ * @var ResponseManagerInterface
*/
private $renderer;
/**
- * @param ConfigInterface $config
- * @param FlasherInterface $flasher
- * @param RendererInterface $renderer
+ * @param ConfigInterface $config
+ * @param FlasherInterface $flasher
+ * @param ResponseManagerInterface $renderer
*/
- public function __construct(ConfigInterface $config, FlasherInterface $flasher, RendererInterface $renderer)
+ public function __construct(ConfigInterface $config, FlasherInterface $flasher, ResponseManagerInterface $renderer)
{
$this->config = $config;
$this->flasher = $flasher;
diff --git a/src/Laravel/ServiceProvider/Providers/Laravel.php b/src/Laravel/ServiceProvider/Providers/Laravel.php
old mode 100644
new mode 100755
index 9580b201..00f946dd
--- a/src/Laravel/ServiceProvider/Providers/Laravel.php
+++ b/src/Laravel/ServiceProvider/Providers/Laravel.php
@@ -14,7 +14,7 @@ use Flasher\Prime\EventDispatcher\EventListener\TemplateListener;
use Flasher\Prime\Factory\NotificationFactory;
use Flasher\Prime\Filter\Filter;
use Flasher\Prime\Flasher;
-use Flasher\Prime\Renderer\Renderer;
+use Flasher\Prime\Response\ResponseManager;
use Flasher\Prime\Storage\StorageManager;
use Illuminate\Container\Container;
use Illuminate\Foundation\Application;
@@ -83,7 +83,7 @@ class Laravel implements ServiceProviderInterface
});
$this->app->singleton('flasher.renderer', function (Application $app) {
- return new Renderer($app['flasher.storage_manager'], $app['flasher.event_dispatcher'], $app['flasher.config']);
+ return new ResponseManager($app['flasher.storage_manager'], $app['flasher.event_dispatcher'], $app['flasher.config']);
});
$this->app->singleton('flasher.storage', function (Application $app) {
diff --git a/src/Noty/Prime/.editorconfig b/src/Noty/Prime/.editorconfig
new file mode 100755
index 00000000..cd8eb86e
--- /dev/null
+++ b/src/Noty/Prime/.editorconfig
@@ -0,0 +1,15 @@
+; This file is for unifying the coding style for different editors and IDEs.
+; More information at http://editorconfig.org
+
+root = true
+
+[*]
+charset = utf-8
+indent_size = 4
+indent_style = space
+end_of_line = lf
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/src/Noty/Symfony/DependencyInjection/Configuration.php b/src/Noty/Symfony/DependencyInjection/Configuration.php
old mode 100644
new mode 100755
index a2edaca4..2249125d
--- a/src/Noty/Symfony/DependencyInjection/Configuration.php
+++ b/src/Noty/Symfony/DependencyInjection/Configuration.php
@@ -39,27 +39,7 @@ final class Configuration implements ConfigurationInterface
->arrayNode('options')
->prototype('variable')->end()
->ignoreExtraKeys(false)
- ->defaultValue(array(
- 'layout' => 'topRight',
- 'theme' => 'mint',
- 'timeout' => 5000,
- 'progressBar' => true,
- 'animation.open' => 'noty_effects_open',
- 'animation.close' => 'noty_effects_close',
- 'sounds.sources' => array(),
- 'closeWith' => array('click'),
- 'sounds.volume' => 1,
- 'sounds.conditions' => array(),
- 'docTitle.conditions' => array(),
- 'modal' => false,
- 'id' => false,
- 'force' => false,
- 'queue' => 'global',
- 'killer' => false,
- 'container' => false,
- 'buttons' => array(),
- 'visibilityControl' => false,
- ))
+ ->defaultValue(array())
->end()
->end()
;
diff --git a/src/Noty/Symfony/DependencyInjection/FlasherNotyExtension.php b/src/Noty/Symfony/DependencyInjection/FlasherNotyExtension.php
old mode 100644
new mode 100755
index 2f27f8ba..65797391
--- a/src/Noty/Symfony/DependencyInjection/FlasherNotyExtension.php
+++ b/src/Noty/Symfony/DependencyInjection/FlasherNotyExtension.php
@@ -2,44 +2,24 @@
namespace Flasher\Noty\Symfony\DependencyInjection;
+use Flasher\Symfony\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
-use Symfony\Component\DependencyInjection\Loader;
-use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-final class FlasherNotyExtension extends Extension implements PrependExtensionInterface
+final class FlasherNotyExtension extends Extension
{
/**
- * {@inheritdoc}
- *
- * @throws \Exception
+ * @inheritDoc
*/
- public function load(array $configs, ContainerBuilder $container)
+ protected function getConfigFileLocator()
{
- $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('config.yaml');
-
- $configuration = new Configuration();
- $this->processConfiguration($configuration, $configs);
+ return new FileLocator(__DIR__.'/../Resources/config');
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
- public function prepend(ContainerBuilder $container)
+ protected function getConfigClass()
{
- if (!$container->hasExtension('flasher')) {
- throw new \RuntimeException('[Flasher\Symfony\FlasherBundle] is not registered');
- }
-
- $configs = $container->getExtensionConfig($this->getAlias());
- $config = $this->processConfiguration(new Configuration(), $configs);
-
- $container->prependExtensionConfig('flasher', array(
- 'adapters' => array(
- 'noty' => $config,
- ),
- ));
+ return new Configuration();
}
}
diff --git a/src/Notyf/Symfony/DependencyInjection/FlasherNotyfExtension.php b/src/Notyf/Symfony/DependencyInjection/FlasherNotyfExtension.php
old mode 100644
new mode 100755
index 1f6da0e6..84b98597
--- a/src/Notyf/Symfony/DependencyInjection/FlasherNotyfExtension.php
+++ b/src/Notyf/Symfony/DependencyInjection/FlasherNotyfExtension.php
@@ -2,44 +2,24 @@
namespace Flasher\Notyf\Symfony\DependencyInjection;
+use Flasher\Symfony\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
-use Symfony\Component\DependencyInjection\Loader;
-use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-final class FlasherNotyfExtension extends Extension implements PrependExtensionInterface
+final class FlasherNotyfExtension extends Extension
{
/**
- * {@inheritdoc}
- *
- * @throws \Exception
+ * @inheritDoc
*/
- public function load(array $configs, ContainerBuilder $container)
+ protected function getConfigFileLocator()
{
- $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('config.yaml');
-
- $configuration = new Configuration();
- $this->processConfiguration($configuration, $configs);
+ return new FileLocator(__DIR__.'/../Resources/config');
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
- public function prepend(ContainerBuilder $container)
+ protected function getConfigClass()
{
- if (!$container->hasExtension('flasher')) {
- throw new \RuntimeException('[Flasher\Symfony\FlasherBundle] is not registered');
- }
-
- $configs = $container->getExtensionConfig($this->getAlias());
- $config = $this->processConfiguration(new Configuration(), $configs);
-
- $container->prependExtensionConfig('flasher', array(
- 'adapters' => array(
- 'notyf' => $config,
- ),
- ));
+ return new Configuration();
}
}
diff --git a/src/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtension.php b/src/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtension.php
old mode 100644
new mode 100755
index 065d888d..f61b5e0b
--- a/src/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtension.php
+++ b/src/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtension.php
@@ -2,44 +2,24 @@
namespace Flasher\Pnotify\Symfony\DependencyInjection;
+use Flasher\Symfony\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
-use Symfony\Component\DependencyInjection\Loader;
-use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-final class FlasherPnotifyExtension extends Extension implements PrependExtensionInterface
+final class FlasherPnotifyExtension extends Extension
{
/**
- * {@inheritdoc}
- *
- * @throws \Exception
+ * @inheritDoc
*/
- public function load(array $configs, ContainerBuilder $container)
+ protected function getConfigFileLocator()
{
- $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('config.yaml');
-
- $configuration = new Configuration();
- $this->processConfiguration($configuration, $configs);
+ return new FileLocator(__DIR__.'/../Resources/config');
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
- public function prepend(ContainerBuilder $container)
+ protected function getConfigClass()
{
- if (!$container->hasExtension('flasher')) {
- throw new \RuntimeException('[Flasher\Symfony\FlasherBundle] is not registered');
- }
-
- $configs = $container->getExtensionConfig($this->getAlias());
- $config = $this->processConfiguration(new Configuration(), $configs);
-
- $container->prependExtensionConfig('flasher', array(
- 'adapters' => array(
- 'pnotify' => $config,
- ),
- ));
+ return new Configuration();
}
}
diff --git a/src/Prime/.editorconfig b/src/Prime/.editorconfig
new file mode 100755
index 00000000..cd8eb86e
--- /dev/null
+++ b/src/Prime/.editorconfig
@@ -0,0 +1,15 @@
+; This file is for unifying the coding style for different editors and IDEs.
+; More information at http://editorconfig.org
+
+root = true
+
+[*]
+charset = utf-8
+indent_size = 4
+indent_style = space
+end_of_line = lf
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/src/Prime/Response/Presenter/ArrayPresenter.php b/src/Prime/Response/Presenter/ArrayPresenter.php
new file mode 100755
index 00000000..6fd60fed
--- /dev/null
+++ b/src/Prime/Response/Presenter/ArrayPresenter.php
@@ -0,0 +1,16 @@
+getEnvelopes())) {
+ return '';
+ }
+
+ $scripts = $this->renderScripts($response->getScripts(), $response->getContext());
+ $options = json_encode($response->toArray());
+
+ return <<
+if ("undefined" === typeof PHPFlasher) {
+ alert("[PHPFlasher] not found, please include ['/path/to/flasher.js'] file");
+} else {
+ PHPFlasher.render({$options});
+}
+
+HTML;
+ }
+
+ /**
+ * @param string[] $scripts
+ * @param array $context
+ *
+ * @return string
+ */
+ public function renderScripts($scripts, array $context)
+ {
+ $html = '';
+
+ foreach ($scripts as $file) {
+ if (empty($context['content']) || false === strpos($context['content'], $file)) {
+ $html .= sprintf('', $file).PHP_EOL;
+ }
+ }
+
+ return $html;
+ }
+}
diff --git a/src/Prime/Response/Presenter/PresenterInterface.php b/src/Prime/Response/Presenter/PresenterInterface.php
new file mode 100755
index 00000000..43e766ef
--- /dev/null
+++ b/src/Prime/Response/Presenter/PresenterInterface.php
@@ -0,0 +1,15 @@
+config = $config;
+ }
+
+ /**
+ * @var array
+ */
+ private $scripts = array();
+
+ /**
+ * @var array
+ */
+ private $styles = array();
+
+ /**
+ * @var array
+ */
+ private $options = array();
+
+ /**
+ * @inheritDoc
+ */
+ public function filterResponse(Response $response)
+ {
+ $response->addScripts($this->config->get('root_scripts', array()));
+
+ $handlers = array();
+
+ foreach ($response->getEnvelopes() as $envelope) {
+ $handler = $envelope->get('Flasher\Prime\Stamp\HandlerStamp')->getHandler();
+ if (in_array($handler, $handlers)) {
+ continue;
+ }
+
+ $handlers[] = $handler;
+
+ if (isset($this->scripts[$handler])) {
+ $response->addScripts($this->scripts[$handler]);
+ }
+
+ if (isset($this->scripts[$handler])) {
+ $response->addStyles($this->styles[$handler]);
+ }
+
+ if (isset($this->scripts[$handler])) {
+ $response->addOptions($handler, $this->options[$handler]);
+ }
+ }
+
+ return $response;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function addScripts($alias, array $scripts)
+ {
+ $this->scripts[$alias] = $scripts;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function addStyles($alias, array $styles)
+ {
+ $this->styles[$alias] = $styles;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function addOptions($alias, array $options)
+ {
+ $this->options[$alias] = $options;
+ }
+}
diff --git a/src/Prime/Response/Resource/ResourceManagerInterface.php b/src/Prime/Response/Resource/ResourceManagerInterface.php
new file mode 100644
index 00000000..91ffec6a
--- /dev/null
+++ b/src/Prime/Response/Resource/ResourceManagerInterface.php
@@ -0,0 +1,33 @@
+
+ */
+ private $options = array();
+
+ /**
+ * @var array
+ */
+ private $context;
+
+ /**
+ * @param array $envelopes
+ * @param array $context
+ */
+ public function __construct(array $envelopes, array $context)
+ {
+ $this->envelopes = $envelopes;
+ $this->context = $context;
+ }
+
+ /**
+ * @param string[] $scripts
+ */
+ public function addScripts(array $scripts)
+ {
+ $this->scripts = array_merge($this->scripts, $scripts);
+ }
+
+ /**
+ * @param string[] $styles
+ */
+ public function addStyles(array $styles)
+ {
+ $this->styles = array_merge($this->styles, $styles);
+ }
+
+ /**
+ * @param string $alias
+ * @param array $options
+ */
+ public function addOptions($alias, array $options)
+ {
+ $this->options[$alias] = $options;
+ }
+
+ /**
+ * @return Envelope[]
+ */
+ public function getEnvelopes()
+ {
+ return $this->envelopes;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getStyles()
+ {
+ return array_values(array_filter(array_unique($this->styles)));
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getScripts()
+ {
+ return array_values(array_filter(array_unique($this->scripts)));
+ }
+
+ /**
+ * @return array[]
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * @return array
+ */
+ public function getContext()
+ {
+ return $this->context;
+ }
+
+ /**
+ * @return array
+ */
+ public function toArray()
+ {
+ return array(
+ 'envelopes' => array_map(
+ function (Envelope $envelope) {
+ return $envelope->toArray();
+ },
+ $this->getEnvelopes()
+ ),
+ 'scripts' => $this->getScripts(),
+ 'styles' => $this->getStyles(),
+ 'options' => $this->getOptions(),
+ );
+ }
+}
diff --git a/src/Prime/Response/ResponseManager.php b/src/Prime/Response/ResponseManager.php
new file mode 100755
index 00000000..a8035e13
--- /dev/null
+++ b/src/Prime/Response/ResponseManager.php
@@ -0,0 +1,115 @@
+storageManager = $storageManager;
+ $this->eventDispatcher = $eventDispatcher;
+ $this->resourceManager = $resourceManager;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function render(array $criteria = array(), $format = 'html', array $context = array())
+ {
+ $envelopes = $this->getEnvelopes($criteria);
+
+ $this->storageManager->remove($envelopes);
+
+ $response = $this->filterResponse($envelopes, $context);
+
+ $presenter = $this->createPresenter($format);
+
+ return $presenter->render($response);
+ }
+
+ /**
+ * @param Envelope[] $envelopes
+ * @param array $context
+ *
+ * @return Response
+ */
+ private function filterResponse($envelopes, $context)
+ {
+ $response = new Response($envelopes, $context);
+
+ return $this->resourceManager->filterResponse($response);
+ }
+
+ /**
+ * @param $alias
+ *
+ * @return PresenterInterface
+ */
+ public function createPresenter($alias)
+ {
+ if (!isset($this->presenters[$alias])) {
+ throw new \InvalidArgumentException(sprintf('[%s] presenter not supported.', $alias));
+ }
+
+ return $this->presenters[$alias];
+ }
+
+ /**
+ * @param string $alias
+ * @param PresenterInterface $presenter
+ */
+ public function addPresenter($alias, PresenterInterface $presenter)
+ {
+ $this->presenters[$alias] = $presenter;
+ }
+
+ /**
+ * @param array $criteria
+ *
+ * @return Envelope[]
+ */
+ private function getEnvelopes(array $criteria)
+ {
+ $envelopes = $this->storageManager->all();
+
+ $event = new FilterEvent($envelopes, $criteria);
+ $this->eventDispatcher->dispatch($event);
+
+ return $event->getEnvelopes();
+ }
+}
diff --git a/src/Prime/Response/ResponseManagerInterface.php b/src/Prime/Response/ResponseManagerInterface.php
new file mode 100755
index 00000000..79ef0b1e
--- /dev/null
+++ b/src/Prime/Response/ResponseManagerInterface.php
@@ -0,0 +1,15 @@
+load('config.yaml');
-
- $configuration = new Configuration();
- $this->processConfiguration($configuration, $configs);
+ return new FileLocator(__DIR__.'/../Resources/config');
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
- public function prepend(ContainerBuilder $container)
+ protected function getConfigClass()
{
- if (!$container->hasExtension('flasher')) {
- throw new \RuntimeException('[Flasher\Symfony\FlasherBundle] is not registered');
- }
-
- $configs = $container->getExtensionConfig($this->getAlias());
- $config = $this->processConfiguration(new Configuration(), $configs);
-
- $container->prependExtensionConfig('flasher', array(
- 'adapters' => array(
- 'sweet_alert' => $config,
- ),
- ));
+ return new Configuration();
}
}
diff --git a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php
new file mode 100755
index 00000000..3b7b92a8
--- /dev/null
+++ b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php
@@ -0,0 +1,30 @@
+has('flasher.response_manager')) {
+ return;
+ }
+
+ /** @var Flasher $manager */
+ $manager = $container->findDefinition('flasher.response_manager');
+
+ foreach ($container->findTaggedServiceIds('flasher.presenter') as $id => $tags) {
+ foreach ($tags as $attributes) {
+ $manager->addMethodCall('addPresenter', array($attributes['alias'], new Reference($id)));
+ }
+ }
+ }
+}
diff --git a/src/Symfony/DependencyInjection/Configuration.php b/src/Symfony/DependencyInjection/Configuration.php
old mode 100644
new mode 100755
index db5da54c..31043d23
--- a/src/Symfony/DependencyInjection/Configuration.php
+++ b/src/Symfony/DependencyInjection/Configuration.php
@@ -25,16 +25,56 @@ final class Configuration implements ConfigurationInterface
->children()
->scalarNode('default')
->cannotBeEmpty()
+ ->defaultValue('toastr')
->end()
- ->arrayNode('scripts')
+ ->arrayNode('root_scripts')
->prototype('scalar')->end()
->defaultValue(array(
- '/bundles/flasher/flasher.js',
- ))
+ '/bundles/flasher/flasher.js',
+ ))
->end()
- ->arrayNode('styles')
- ->prototype('scalar')->end()
- ->defaultValue(array())
+ ->arrayNode('template_factory')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->scalarNode('default')
+ ->isRequired()
+ ->cannotBeEmpty()
+ ->defaultValue('tailwindcss')
+ ->end()
+ ->arrayNode('templates')
+ ->ignoreExtraKeys()
+ ->prototype('scalar')->end()
+ ->children()
+ ->scalarNode('view')
+ ->isRequired()
+ ->cannotBeEmpty()
+ ->end()
+ ->arrayNode('styles')->end()
+ ->arrayNode('scripts')->end()
+ ->arrayNode('options')->end()
+ ->end()
+ ->defaultValue(array(
+ 'tailwindcss' => array(
+ 'view' => '@Flasher/tailwindcss.html.twig',
+ 'styles' => array(
+ 'https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css',
+ ),
+ ),
+ 'tailwindcss_bg' => array(
+ 'view' => '@Flasher/tailwindcss_bg.html.twig',
+ 'styles' => array(
+ 'https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css',
+ ),
+ ),
+ 'bootstrap' => array(
+ 'view' => '@Flasher/bootstrap.html.twig',
+ 'styles' => array(
+ 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css',
+ ),
+ ),
+ ))
+ ->end()
+ ->end()
->end()
->booleanNode('auto_create_from_session')
->defaultValue(true)
@@ -48,11 +88,6 @@ final class Configuration implements ConfigurationInterface
'info' => array('info', 'notice', 'alert'),
))
->end()
- ->arrayNode('adapters')
- ->ignoreExtraKeys(false)
- ->useAttributeAsKey('name')
- ->prototype('variable')->end()
- ->end()
->end()
;
diff --git a/src/Symfony/DependencyInjection/Extension.php b/src/Symfony/DependencyInjection/Extension.php
new file mode 100755
index 00000000..ea8e9630
--- /dev/null
+++ b/src/Symfony/DependencyInjection/Extension.php
@@ -0,0 +1,88 @@
+getAlias());
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @throws \Exception
+ */
+ public function load(array $configs, ContainerBuilder $container)
+ {
+ $loader = new Loader\YamlFileLoader(
+ $container,
+ $this->getConfigFileLocator()
+ );
+ $loader->load('config.yaml');
+ }
+
+ /**
+ * @param array $config
+ *
+ * @return array
+ */
+ protected function getScripts($config)
+ {
+ return isset($config['scripts']) ? $config['scripts'] : array();
+ }
+
+ /**
+ * @param array $config
+ *
+ * @return array
+ */
+ protected function getStyles($config)
+ {
+ return isset($config['styles']) ? $config['styles'] : array();
+ }
+
+ /**
+ * @param array $config
+ *
+ * @return array
+ */
+ protected function getOptions($config)
+ {
+ return isset($config['options']) ? $config['options'] : array();
+ }
+
+ /**
+ * @param ContainerBuilder $container
+ */
+ public function process(ContainerBuilder $container)
+ {
+ $configs = $container->getExtensionConfig($this->getAlias());
+ $config = $this->processConfiguration($this->getConfigClass(), $configs);
+
+ $responseManager = $container->getDefinition('flasher.resource_manager');
+ $responseManager->addMethodCall('addScripts', array($this->getHandlerAlias(), $this->getScripts($config)));
+ $responseManager->addMethodCall('addStyles', array($this->getHandlerAlias(), $this->getStyles($config)));
+ $responseManager->addMethodCall('addOptions', array($this->getHandlerAlias(), $this->getOptions($config)));
+ }
+}
diff --git a/src/Symfony/DependencyInjection/FlasherExtension.php b/src/Symfony/DependencyInjection/FlasherExtension.php
old mode 100644
new mode 100755
index 7661e4ab..e04a5484
--- a/src/Symfony/DependencyInjection/FlasherExtension.php
+++ b/src/Symfony/DependencyInjection/FlasherExtension.php
@@ -11,18 +11,31 @@ final class FlasherExtension extends Extension
{
/**
* {@inheritdoc}
- *
- * @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
{
- $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader = new Loader\YamlFileLoader(
+ $container,
+ new FileLocator(__DIR__.'/../Resources/config')
+ );
$loader->load('config.yaml');
- $configuration = new Configuration();
- $config = $this->processConfiguration($configuration, $configs);
+ $configration = $this->processConfiguration(new Configuration(), $configs);
- $notifyConfig = $container->getDefinition('flasher.config');
- $notifyConfig->replaceArgument(0, $config);
+ $config = $container->getDefinition('flasher.config');
+ $config->replaceArgument(0, $configration);
+
+// $responseManager = $container->getDefinition('flasher.response_manager');
+// foreach ($configration['template_factory']['templates'] as $template => $factory) {
+// if (isset($factory['scripts'])) {
+// $responseManager->addMethodCall('addScripts', array('template_'.$template, $factory['scripts']));
+// }
+// if (isset($factory['styles'])) {
+// $responseManager->addMethodCall('addStyles', array('template_'.$template, $factory['styles']));
+// }
+// if (isset($factory['options'])) {
+// $responseManager->addMethodCall('addOptions', array('template_'.$template, $factory['options']));
+// }
+// }
}
}
diff --git a/src/Symfony/EventListener/SessionListener.php b/src/Symfony/EventListener/SessionListener.php
old mode 100644
new mode 100755
index e6fd21a3..df65a2b5
--- a/src/Symfony/EventListener/SessionListener.php
+++ b/src/Symfony/EventListener/SessionListener.php
@@ -4,7 +4,7 @@ namespace Flasher\Symfony\EventListener;
use Flasher\Prime\Config\ConfigInterface;
use Flasher\Prime\FlasherInterface;
-use Flasher\Prime\Renderer\RendererInterface;
+use Flasher\Prime\Response\ResponseManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
@@ -21,16 +21,16 @@ final class SessionListener implements EventSubscriberInterface
private $flasher;
/**
- * @var RendererInterface
+ * @var ResponseManagerInterface
*/
private $renderer;
/**
- * @param ConfigInterface $config
- * @param FlasherInterface $flasher
- * @param RendererInterface $renderer
+ * @param ConfigInterface $config
+ * @param FlasherInterface $flasher
+ * @param ResponseManagerInterface $renderer
*/
- public function __construct(ConfigInterface $config, FlasherInterface $flasher, RendererInterface $renderer)
+ public function __construct(ConfigInterface $config, FlasherInterface $flasher, ResponseManagerInterface $renderer)
{
$this->config = $config;
$this->flasher = $flasher;
@@ -69,8 +69,7 @@ final class SessionListener implements EventSubscriberInterface
$content = $response->getContent();
- $htmlResponse = $this->renderer->render(array(), array(
- 'format' => 'html',
+ $htmlResponse = $this->renderer->render(array(), 'html', array(
'content' => $content,
));
diff --git a/src/Symfony/FlasherBundle.php b/src/Symfony/FlasherBundle.php
old mode 100644
new mode 100755
index bf98e38f..c3d60264
--- a/src/Symfony/FlasherBundle.php
+++ b/src/Symfony/FlasherBundle.php
@@ -4,6 +4,7 @@ namespace Flasher\Symfony;
use Flasher\Symfony\DependencyInjection\Compiler\EventSubscriberCompilerPass;
use Flasher\Symfony\DependencyInjection\Compiler\FactoryCompilerPass;
+use Flasher\Symfony\DependencyInjection\Compiler\PresenterCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -16,5 +17,6 @@ class FlasherBundle extends Bundle
{
$container->addCompilerPass(new FactoryCompilerPass());
$container->addCompilerPass(new EventSubscriberCompilerPass());
+ $container->addCompilerPass(new PresenterCompilerPass());
}
}
diff --git a/src/Symfony/Resources/config/config.yaml b/src/Symfony/Resources/config/config.yaml
old mode 100644
new mode 100755
index 52d4fb72..a0e192e4
--- a/src/Symfony/Resources/config/config.yaml
+++ b/src/Symfony/Resources/config/config.yaml
@@ -5,7 +5,7 @@ services:
flasher.config:
class: Flasher\Prime\Config\Config
arguments:
- - null
+ - []
flasher:
class: Flasher\Prime\Flasher
@@ -68,23 +68,38 @@ services:
flasher.twig.extension:
class: Flasher\Symfony\Twig\FlasherTwigExtension
arguments:
- - '@flasher.renderer'
+ - '@flasher.response_manager'
tags:
- { name: 'twig.extension' }
- flasher.renderer:
- class: Flasher\Prime\Renderer\Renderer
+ flasher.resource_manager:
+ class: Flasher\Prime\Response\Resource\ResourceManager
+ arguments:
+ - '@flasher.config'
+
+ flasher.response_manager:
+ class: Flasher\Prime\Response\ResponseManager
arguments:
- '@flasher.storage_manager'
- '@flasher.event_dispatcher'
- - '@flasher.config'
+ - '@flasher.resource_manager'
+
+ flasher.presenter.html:
+ class: Flasher\Prime\Response\Presenter\HtmlPresenter
+ tags:
+ - { name: 'flasher.presenter', alias: 'html' }
+
+ flasher.presenter.array:
+ class: Flasher\Prime\Response\Presenter\ArrayPresenter
+ tags:
+ - { name: 'flasher.presenter', alias: 'array' }
flasher.session_listener:
class: Flasher\Symfony\EventListener\SessionListener
arguments:
- '@flasher.config'
- '@flasher'
- - '@flasher.renderer'
+ - '@flasher.response_manager'
tags:
- { name: 'kernel.event_subscriber' }
@@ -95,7 +110,6 @@ services:
Flasher\Prime\Config\Config: '@flasher.config'
Flasher\Prime\Flasher: '@flasher'
- Flasher\Prime\Renderer\Renderer: '@flasher.renderer'
Flasher\Prime\EventDispatcher\EventDispatcher: '@flasher.event_dispatcher'
Flasher\Symfony\Storage\Storage: '@flasher.storage'
Flasher\Prime\Storage\StorageManager: '@flasher.storage_manager'
@@ -106,7 +120,6 @@ services:
Flasher\Prime\Config\ConfigInterface: '@flasher.config'
Flasher\Prime\FlasherInterface: '@flasher'
Flasher\Prime\Storage\StorageManagerInterface: '@flasher.storage_manager'
- Flasher\Prime\Renderer\RendererInterface: '@flasher.renderer'
Flasher\Prime\Filter\FilterInterface: '@flasher.filter'
Flasher\Prime\EventDispatcher\EventDispatcherInterface: '@flasher.event_dispatcher'
Flasher\Prime\Storage\StorageInterface: '@flasher.storage'
diff --git a/src/Symfony/Tests/Twig/FlasherTwigExtensionTest.php b/src/Symfony/Tests/Twig/FlasherTwigExtensionTest.php
old mode 100644
new mode 100755
index 31cf169f..ab7b2e05
--- a/src/Symfony/Tests/Twig/FlasherTwigExtensionTest.php
+++ b/src/Symfony/Tests/Twig/FlasherTwigExtensionTest.php
@@ -2,7 +2,7 @@
namespace Flasher\Symfony\Tests\Twig;
-use Flasher\Prime\Renderer\RendererInterface;
+use Flasher\Prime\Response\ResponseManagerInterface;
use Flasher\Prime\Tests\TestCase;
use Flasher\Symfony\Twig\FlasherTwigExtension;
use Twig\Environment;
@@ -20,7 +20,7 @@ class FlasherTwigExtensionTest extends TestCase
$this->assertEquals($expected, $this->render('{{ flasher_render() }}', $renderer));
}
- private function render($template, RendererInterface $renderer)
+ private function render($template, ResponseManagerInterface $renderer)
{
$twig = new Environment(new ArrayLoader(array('template' => $template)), array(
'debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0,
diff --git a/src/Symfony/Twig/FlasherTwigExtension.php b/src/Symfony/Twig/FlasherTwigExtension.php
old mode 100644
new mode 100755
index bb954c05..32c9d5e6
--- a/src/Symfony/Twig/FlasherTwigExtension.php
+++ b/src/Symfony/Twig/FlasherTwigExtension.php
@@ -2,21 +2,21 @@
namespace Flasher\Symfony\Twig;
-use Flasher\Prime\Renderer\RendererInterface;
+use Flasher\Prime\Response\ResponseManagerInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class FlasherTwigExtension extends AbstractExtension
{
/**
- * @var RendererInterface
+ * @var ResponseManagerInterface
*/
private $renderer;
/**
- * @param RendererInterface $renderer
+ * @param ResponseManagerInterface $renderer
*/
- public function __construct(RendererInterface $renderer)
+ public function __construct(ResponseManagerInterface $renderer)
{
$this->renderer = $renderer;
}
@@ -37,8 +37,6 @@ final class FlasherTwigExtension extends AbstractExtension
*/
public function flasherRender(array $criteria = array())
{
- return $this->renderer->render($criteria, array(
- 'format' => 'html',
- ));
+ return $this->renderer->render($criteria);
}
}
diff --git a/src/Toastr/Prime/.editorconfig b/src/Toastr/Prime/.editorconfig
new file mode 100755
index 00000000..cd8eb86e
--- /dev/null
+++ b/src/Toastr/Prime/.editorconfig
@@ -0,0 +1,15 @@
+; This file is for unifying the coding style for different editors and IDEs.
+; More information at http://editorconfig.org
+
+root = true
+
+[*]
+charset = utf-8
+indent_size = 4
+indent_style = space
+end_of_line = lf
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/src/Toastr/Symfony/DependencyInjection/Configuration.php b/src/Toastr/Symfony/DependencyInjection/Configuration.php
old mode 100644
new mode 100755
index 77e60bee..9ed4009a
--- a/src/Toastr/Symfony/DependencyInjection/Configuration.php
+++ b/src/Toastr/Symfony/DependencyInjection/Configuration.php
@@ -39,47 +39,7 @@ final class Configuration implements ConfigurationInterface
->end()
->arrayNode('options')
->prototype('variable')->end()
- ->ignoreExtraKeys(false)
- ->defaultValue(array(
- 'closeButton' => true,
- 'closeClass' => 'toast-close-button',
- 'closeDuration' => 300,
- 'closeEasing' => 'swing',
- 'closeHtml' => '',
- 'closeMethod' => 'fadeOut',
- 'closeOnHover' => true,
- 'containerId' => 'toast-container',
- 'debug' => false,
- 'escapeHtml' => false,
- 'extendedTimeOut' => 10000,
- 'hideDuration' => 1000,
- 'hideEasing' => 'linear',
- 'hideMethod' => 'fadeOut',
- 'iconClass' => 'toast-info',
- 'iconClasses' => array(
- 'error' => 'toast-error',
- 'info' => 'toast-info',
- 'success' => 'toast-success',
- 'warning' => 'toast-warning',
- ),
- 'messageClass' => 'toast-message',
- 'newestOnTop' => false,
- 'onHidden' => null,
- 'onShown' => null,
- 'positionClass' => 'toast-top-right',
- 'preventDuplicates' => false,
- 'progressBar' => true,
- 'progressClass' => 'toast-progress',
- 'rtl' => false,
- 'showDuration' => 300,
- 'showEasing' => 'swing',
- 'showMethod' => 'fadeIn',
- 'tapToDismiss' => true,
- 'target' => 'body',
- 'timeOut' => 5000,
- 'titleClass' => 'toast-title',
- 'toastClass' => 'toast',
- ))
+ ->defaultValue(array())
->end()
->end()
;
diff --git a/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php b/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php
old mode 100644
new mode 100755
index b623aa64..43daf93c
--- a/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php
+++ b/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php
@@ -2,44 +2,24 @@
namespace Flasher\Toastr\Symfony\DependencyInjection;
+use Flasher\Symfony\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
-use Symfony\Component\DependencyInjection\Loader;
-use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-final class FlasherToastrExtension extends Extension implements PrependExtensionInterface
+final class FlasherToastrExtension extends Extension
{
/**
- * {@inheritdoc}
- *
- * @throws \Exception
+ * @inheritDoc
*/
- public function load(array $configs, ContainerBuilder $container)
+ protected function getConfigFileLocator()
{
- $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('config.yaml');
-
- $configuration = new Configuration();
- $this->processConfiguration($configuration, $configs);
+ return new FileLocator(__DIR__.'/../Resources/config');
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
- public function prepend(ContainerBuilder $container)
+ protected function getConfigClass()
{
- if (!$container->hasExtension('flasher')) {
- throw new \RuntimeException('[Flasher\Symfony\FlasherBundle] is not registered');
- }
-
- $configs = $container->getExtensionConfig($this->getAlias());
- $config = $this->processConfiguration(new Configuration(), $configs);
-
- $container->prependExtensionConfig('flasher', array(
- 'adapters' => array(
- 'toastr' => $config,
- ),
- ));
+ return new Configuration();
}
}