mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
refactor symfony bundle configuration and response manager
This commit is contained in:
Regular → Executable
+2
-12
@@ -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"
|
||||
}
|
||||
|
||||
Regular → Executable
+6
-6
@@ -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;
|
||||
|
||||
Regular → Executable
+2
-2
@@ -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) {
|
||||
|
||||
Executable
+15
@@ -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
|
||||
Regular → Executable
+1
-21
@@ -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()
|
||||
;
|
||||
|
||||
Regular → Executable
+8
-28
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+8
-28
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+8
-28
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+15
@@ -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
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response\Presenter;
|
||||
|
||||
use Flasher\Prime\Response\Response;
|
||||
|
||||
final class ArrayPresenter implements PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function render(Response $response)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response\Presenter;
|
||||
|
||||
use Flasher\Prime\Response\Response;
|
||||
|
||||
final class HtmlPresenter implements PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function render(Response $response)
|
||||
{
|
||||
if (0 === count($response->getEnvelopes())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$scripts = $this->renderScripts($response->getScripts(), $response->getContext());
|
||||
$options = json_encode($response->toArray());
|
||||
|
||||
return <<<HTML
|
||||
{$scripts}
|
||||
<script type="text/javascript">
|
||||
if ("undefined" === typeof PHPFlasher) {
|
||||
alert("[PHPFlasher] not found, please include ['/path/to/flasher.js'] file");
|
||||
} else {
|
||||
PHPFlasher.render({$options});
|
||||
}
|
||||
</script>
|
||||
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('<script src="%s"></script>', $file).PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response\Presenter;
|
||||
|
||||
use Flasher\Prime\Response\Response;
|
||||
|
||||
interface PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @param Response $response
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render(Response $response);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response\Resource;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Response\Response;
|
||||
|
||||
final class ResourceManager implements ResourceManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param ConfigInterface $config
|
||||
*/
|
||||
public function __construct(ConfigInterface $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array<string, string[]>
|
||||
*/
|
||||
private $scripts = array();
|
||||
|
||||
/**
|
||||
* @var array<string, string[]>
|
||||
*/
|
||||
private $styles = array();
|
||||
|
||||
/**
|
||||
* @var array<string, 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response\Resource;
|
||||
|
||||
use Flasher\Prime\Response\Response;
|
||||
|
||||
interface ResourceManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param Response $response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function filterResponse(Response $response);
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
* @param string[] $scripts
|
||||
*/
|
||||
public function addScripts($alias, array $scripts);
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
* @param string[] $styles
|
||||
*/
|
||||
public function addStyles($alias, array $styles);
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
* @param array $options
|
||||
*/
|
||||
public function addOptions($alias, array $options);
|
||||
}
|
||||
Executable
+126
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
|
||||
final class Response
|
||||
{
|
||||
/**
|
||||
* @var Envelope[]
|
||||
*/
|
||||
private $envelopes;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $scripts = array();
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $styles = array();
|
||||
|
||||
/**
|
||||
* @var array<string, array>
|
||||
*/
|
||||
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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\EventDispatcher\Event\FilterEvent;
|
||||
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
|
||||
use Flasher\Prime\Response\Resource\ResourceManagerInterface;
|
||||
use Flasher\Prime\Response\Presenter\PresenterInterface;
|
||||
use Flasher\Prime\Storage\StorageManagerInterface;
|
||||
|
||||
final class ResponseManager implements ResponseManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var PresenterInterface[]
|
||||
*/
|
||||
private $presenters;
|
||||
|
||||
/**
|
||||
* @var StorageManagerInterface
|
||||
*/
|
||||
private $storageManager;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var ResourceManagerInterface
|
||||
*/
|
||||
private $resourceManager;
|
||||
|
||||
/**
|
||||
* @param StorageManagerInterface $storageManager
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param ResourceManagerInterface $resourceManager
|
||||
*/
|
||||
public function __construct(
|
||||
StorageManagerInterface $storageManager,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
ResourceManagerInterface $resourceManager
|
||||
) {
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Response;
|
||||
|
||||
interface ResponseManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param array $criteria
|
||||
* @param string $format
|
||||
* @param array $context
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render(array $criteria = array(), $format = 'html', array $context = array());
|
||||
}
|
||||
Regular → Executable
+8
-28
@@ -2,44 +2,24 @@
|
||||
|
||||
namespace Flasher\SweetAlert\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 FlasherSweetAlertExtension extends Extension implements PrependExtensionInterface
|
||||
final class FlasherSweetAlertExtension 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(
|
||||
'sweet_alert' => $config,
|
||||
),
|
||||
));
|
||||
return new Configuration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Symfony\DependencyInjection\Compiler;
|
||||
|
||||
use Flasher\Prime\Flasher;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class PresenterCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Regular → Executable
+46
-11
@@ -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()
|
||||
;
|
||||
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Symfony\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocatorInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension as SymfonyExtension;
|
||||
|
||||
abstract class Extension extends SymfonyExtension implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* @return FileLocatorInterface
|
||||
*/
|
||||
protected abstract function getConfigFileLocator();
|
||||
|
||||
/**
|
||||
* @return ConfigurationInterface
|
||||
*/
|
||||
protected abstract function getConfigClass();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getHandlerAlias()
|
||||
{
|
||||
return str_replace('flasher_', '', $this->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)));
|
||||
}
|
||||
}
|
||||
Regular → Executable
+20
-7
@@ -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']));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+7
-8
@@ -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,
|
||||
));
|
||||
|
||||
|
||||
Regular → Executable
+2
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+21
-8
@@ -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'
|
||||
|
||||
Regular → Executable
+2
-2
@@ -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,
|
||||
|
||||
Regular → Executable
+5
-7
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+15
@@ -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
|
||||
Regular → Executable
+1
-41
@@ -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' => '<button><i class="icon-off"></i></button>',
|
||||
'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()
|
||||
;
|
||||
|
||||
Regular → Executable
+8
-28
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user