Compare commits

...

5 Commits

Author SHA1 Message Date
KHOUBZA Younes 60a76cf1c3 rename symfony extensions 2021-04-17 18:13:10 +02:00
KHOUBZA Younes 3f0087d7c3 rename symfony bundles names to fix symfony flex bundle auto register 2021-04-17 17:57:12 +02:00
KHOUBZA Younes 5492d30374 update composer.json 2021-04-16 20:26:48 +02:00
KHOUBZA Younes 7ff1ec4fc1 clean up code 2021-04-16 20:08:36 +02:00
KHOUBZA Younes e6237cbe42 refactor symfony bundle configuration and response manager 2021-02-09 05:15:19 +01:00
9 changed files with 126 additions and 170 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
.idea/
vendor/
.idea
vendor
composer.lock
.phpunit.result.cache
.phpcs-cache
+5 -44
View File
@@ -26,59 +26,20 @@ final class Configuration implements ConfigurationInterface
->arrayNode('scripts')
->prototype('scalar')->end()
->defaultValue(array(
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js',
'/bundles/flashertoastr/flasher-toastr.js',
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js',
'https://cdn.jsdelivr.net/npm/@flasher/flasher-toastr@0.1.3/dist/flasher-toastr.min.js',
))
->end()
->arrayNode('styles')
->prototype('scalar')->end()
->defaultValue(array(
'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css',
))
->defaultValue(array())
->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',
'progressBar' => true,
'timeOut' => 5000,
))
->end()
->end()
@@ -1,45 +0,0 @@
<?php
namespace Flasher\Toastr\Symfony\DependencyInjection;
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
{
/**
* {@inheritdoc}
*
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yaml');
$configuration = new Configuration();
$this->processConfiguration($configuration, $configs);
}
/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container)
{
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,
),
));
}
}
@@ -0,0 +1,25 @@
<?php
namespace Flasher\Toastr\Symfony\DependencyInjection;
use Flasher\Symfony\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
final class FlasherToastrSymfonyExtension extends Extension
{
/**
* @inheritDoc
*/
protected function getConfigFileLocator()
{
return new FileLocator(__DIR__.'/../Resources/config');
}
/**
* @inheritDoc
*/
protected function getConfigClass()
{
return new Configuration();
}
}
@@ -4,6 +4,6 @@ namespace Flasher\Toastr\Symfony;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class FlasherToastrBundle extends Bundle
class FlasherToastrSymfonyBundle extends Bundle
{
}
-16
View File
@@ -1,16 +0,0 @@
PHPFlasher.addFactory('toastr', (function () {
'use strict';
var exports = {};
exports.render = function (data) {
var notification = data.notification;
toastr[notification.type](notification.message, notification.title, notification.options);
};
exports.renderOptions = function (options) {
toastr.options = options;
};
return exports;
})());
@@ -13,54 +13,15 @@ class ConfigurationTest extends TestCase
$config = $this->process(array());
$expected = array(
'scripts' => array(
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js',
'/bundles/flashertoastr/flasher-toastr.js',
'scripts' => array(
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js',
'https://cdn.jsdelivr.net/npm/@flasher/flasher-toastr@0.1.3/dist/flasher-toastr.min.js',
),
'styles' => array(
'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css',
),
'options' =>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',
)
'styles' => array(),
'options' => array(
'progressBar' => true,
'timeOut' => 5000,
)
);
$this->assertSame($expected, $config);
@@ -3,10 +3,10 @@
namespace Flasher\Toastr\Symfony\Tests\DependencyInjection;
use Flasher\Prime\Tests\TestCase;
use Flasher\Symfony\DependencyInjection\FlasherExtension;
use Flasher\Symfony\FlasherBundle;
use Flasher\Toastr\Symfony\DependencyInjection\FlasherToastrExtension;
use Flasher\Toastr\Symfony\FlasherToastrBundle;
use Flasher\Symfony\DependencyInjection\FlasherSymfonyExtension;
use Flasher\Symfony\FlasherSymfonyBundle;
use Flasher\Toastr\Symfony\DependencyInjection\FlasherToastrSymfonyExtension;
use Flasher\Toastr\Symfony\FlasherToastrSymfonyBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class FlasherToastrExtensionTest extends TestCase
@@ -41,23 +41,16 @@ class FlasherToastrExtensionTest extends TestCase
$this->assertSame('flasher.toastr', (string) $calls[1][1][1]);
}
public function testConfigurationInjectedIntoFlasherConfig()
{
$container = $this->getContainer();
$config = $container->get('flasher.config');
$this->assertNotEmpty($config->get('adapters.toastr'));
}
private function getRawContainer()
{
$container = new ContainerBuilder();
$container->registerExtension(new FlasherExtension());
$flasherBundle = new FlasherBundle();
$container->registerExtension(new FlasherSymfonyExtension());
$flasherBundle = new FlasherSymfonyBundle();
$flasherBundle->build($container);
$container->registerExtension(new FlasherToastrExtension());
$adapterBundle = new FlasherToastrBundle();
$container->registerExtension(new FlasherToastrSymfonyExtension());
$adapterBundle = new FlasherToastrSymfonyBundle();
$adapterBundle->build($container);
$container->getCompilerPassConfig()->setOptimizationPasses(array());
@@ -70,6 +63,8 @@ class FlasherToastrExtensionTest extends TestCase
private function getContainer()
{
$container = $this->getRawContainer();
$container->loadFromExtension('flasher', array());
$container->loadFromExtension('flasher_toastr', array());
$container->compile();
return $container;
+75
View File
@@ -0,0 +1,75 @@
{
"name": "php-flasher/flasher-toastr-symfony",
"type": "symfony-bundle",
"description": "PHP Flasher Symfony adapter for Toastr",
"keywords": [
"yoeunes",
"notify",
"php",
"laravel",
"symfony",
"Lumen",
"notifications",
"messages",
"alerts",
"pnotify",
"toastr ",
"bundle",
"flex"
],
"homepage": "https://php-flasher.github.io/",
"authors": [
{
"name": "Younes Khoubza",
"email": "younes.khoubza@gmail.com",
"homepage": "https://github.com/yoeunes",
"role": "Developer"
}
],
"license": "MIT",
"repositories": [
{
"type": "path",
"url": "../../Symfony",
"options": {
"symlink": true
}
},
{
"type": "path",
"url": "../Prime",
"options": {
"symlink": true
}
}
],
"require": {
"php": ">=5.3",
"php-flasher/flasher-symfony": "@dev",
"php-flasher/flasher-toastr": "@dev"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0|^9.0"
},
"autoload": {
"psr-4": {
"Flasher\\Toastr\\Symfony\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"autoload-dev": {
"psr-4": {
"Flasher\\Toastr\\Symfony\\Tests\\": "Tests/"
}
},
"config": {
"sort-packages": true,
"platform": {
"php": "5.3.10"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}