first commit
This commit is contained in:
289
vendor/php-flasher/flasher/Plugin/FlasherPlugin.php
vendored
Normal file
289
vendor/php-flasher/flasher/Plugin/FlasherPlugin.php
vendored
Normal file
@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the PHPFlasher package.
|
||||
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Flasher\Prime\Plugin;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Notification\NotificationInterface;
|
||||
|
||||
/**
|
||||
* @phpstan-import-type ConfigType from ConfigInterface
|
||||
*/
|
||||
final class FlasherPlugin extends Plugin
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'flasher';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getServiceID()
|
||||
{
|
||||
return 'flasher';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return 'flasher';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array{cdn: string, local: string}
|
||||
*/
|
||||
public function getRootScript()
|
||||
{
|
||||
return array(
|
||||
'cdn' => 'https://cdn.jsdelivr.net/npm/@flasher/flasher@1.3.2/dist/flasher.min.js',
|
||||
'local' => '/vendor/flasher/flasher.min.js',
|
||||
);
|
||||
}
|
||||
|
||||
public function getScripts()
|
||||
{
|
||||
$rootScript = $this->getRootScript();
|
||||
|
||||
return array(
|
||||
'cdn' => is_string($rootScript) ? array($rootScript) : array($rootScript['cdn']),
|
||||
'local' => is_string($rootScript) ? '' : array($rootScript['local']),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getStyles()
|
||||
{
|
||||
return array(
|
||||
'cdn' => array(
|
||||
'https://cdn.jsdelivr.net/npm/@flasher/flasher@1.3.2/dist/flasher.min.css',
|
||||
),
|
||||
'local' => array(
|
||||
'/vendor/flasher/flasher.min.css',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResourcesDir()
|
||||
{
|
||||
return realpath(__DIR__.'/../Resources') ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string[]>
|
||||
*/
|
||||
public function getFlashBagMapping()
|
||||
{
|
||||
return array(
|
||||
'success' => array('success'),
|
||||
'error' => array('error', 'danger'),
|
||||
'warning' => array('warning', 'alarm'),
|
||||
'info' => array('info', 'notice', 'alert'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processConfiguration(array $options = array())
|
||||
{
|
||||
$options = $this->normalizeConfig($options); // @phpstan-ignore-line
|
||||
|
||||
return array_merge(array(
|
||||
'default' => $this->getDefault(),
|
||||
'root_script' => $this->getRootScript(),
|
||||
'scripts' => array(),
|
||||
'styles' => $this->getStyles(),
|
||||
'options' => array(),
|
||||
'use_cdn' => true,
|
||||
'auto_translate' => true,
|
||||
'auto_render' => true,
|
||||
'flash_bag' => array(
|
||||
'enabled' => true,
|
||||
'mapping' => $this->getFlashBagMapping(),
|
||||
),
|
||||
'filter_criteria' => array(),
|
||||
), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{
|
||||
* root_script?: string|array,
|
||||
* styles?: string|array,
|
||||
* scripts ?: string|array,
|
||||
* template_factory?: array{default: string, templates: array<string, array<string, string>>},
|
||||
* auto_create_from_session?: bool,
|
||||
* auto_render?: bool,
|
||||
* types_mapping?: array<string, string>,
|
||||
* observer_events?: array<string, string>,
|
||||
* translate_by_default?: bool,
|
||||
* presets?: array<string, array{
|
||||
* type: string,
|
||||
* title: string,
|
||||
* message: string,
|
||||
* options: array<string, mixed>,
|
||||
* }>,
|
||||
* } $config
|
||||
*
|
||||
* @phpstan-return ConfigType
|
||||
*/
|
||||
public function normalizeConfig(array $config)
|
||||
{
|
||||
if (isset($config['root_script']) && is_string($config['root_script'])) {
|
||||
$config['root_script'] = array(
|
||||
'local' => $config['root_script'],
|
||||
'cdn' => $config['root_script'],
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($config['styles'])) {
|
||||
if (is_string($config['styles'])) {
|
||||
$config['styles'] = array('cdn' => $config['styles'], 'local' => $config['styles']);
|
||||
}
|
||||
|
||||
$config['styles'] = array_merge(array('cdn' => array(), 'local' => array()), $config['styles']);
|
||||
|
||||
$config['styles']['cdn'] = (array) $config['styles']['cdn'];
|
||||
$config['styles']['local'] = (array) $config['styles']['local'];
|
||||
}
|
||||
|
||||
if (isset($config['scripts'])) {
|
||||
if (is_string($config['scripts'])) {
|
||||
$config['scripts'] = array('cdn' => $config['scripts'], 'local' => $config['scripts']);
|
||||
}
|
||||
|
||||
$config['scripts'] = array_merge(array('cdn' => array(), 'local' => array()), $config['scripts']);
|
||||
|
||||
$config['scripts']['cdn'] = (array) $config['scripts']['cdn'];
|
||||
$config['scripts']['local'] = (array) $config['scripts']['local'];
|
||||
}
|
||||
|
||||
$deprecatedKeys = array();
|
||||
|
||||
if (isset($config['template_factory']['default'])) {
|
||||
$deprecatedKeys[] = 'template_factory.default';
|
||||
unset($config['template_factory']['default']);
|
||||
}
|
||||
|
||||
if (isset($config['template_factory']['templates'])) {
|
||||
$deprecatedKeys[] = 'template_factory.templates';
|
||||
$config['themes'] = $config['template_factory']['templates'];
|
||||
unset($config['template_factory']['templates']);
|
||||
}
|
||||
|
||||
unset($config['template_factory']);
|
||||
|
||||
if (isset($config['themes']['flasher']['options'])) {
|
||||
$deprecatedKeys[] = 'themes.flasher.options';
|
||||
$config['options'] = $config['themes']['flasher']['options'];
|
||||
unset($config['themes']['flasher']['options']);
|
||||
}
|
||||
|
||||
if (isset($config['auto_create_from_session'])) {
|
||||
$deprecatedKeys[] = 'auto_create_from_session';
|
||||
$config['flash_bag']['enabled'] = $config['auto_create_from_session'];
|
||||
unset($config['auto_create_from_session']);
|
||||
}
|
||||
|
||||
if (isset($config['types_mapping'])) {
|
||||
$deprecatedKeys[] = 'types_mapping';
|
||||
$config['flash_bag']['mapping'] = $config['types_mapping'];
|
||||
unset($config['types_mapping']);
|
||||
}
|
||||
|
||||
if (isset($config['observer_events'])) {
|
||||
$deprecatedKeys[] = 'observer_events';
|
||||
unset($config['observer_events']);
|
||||
}
|
||||
|
||||
if (isset($config['translate_by_default'])) {
|
||||
$deprecatedKeys[] = 'translate_by_default';
|
||||
$config['auto_translate'] = $config['translate_by_default'];
|
||||
unset($config['translate_by_default']);
|
||||
}
|
||||
|
||||
if (array() !== $deprecatedKeys) {
|
||||
@trigger_error(sprintf('Since php-flasher/flasher-laravel v1.0: The following configuration keys are deprecated and will be removed in v2.0: %s. Please use the new configuration structure.', implode(', ', $deprecatedKeys)), \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (\array_key_exists('flash_bag', $config)) {
|
||||
$config['flash_bag'] = $this->normalizeFlashBagConfig($config['flash_bag']);
|
||||
}
|
||||
|
||||
$config['presets'] = array_merge(array(
|
||||
'created' => array(
|
||||
'type' => NotificationInterface::SUCCESS,
|
||||
'message' => 'The resource was created',
|
||||
),
|
||||
'updated' => array(
|
||||
'type' => NotificationInterface::SUCCESS,
|
||||
'message' => 'The resource was updated',
|
||||
),
|
||||
'saved' => array(
|
||||
'type' => NotificationInterface::SUCCESS,
|
||||
'message' => 'The resource was saved',
|
||||
),
|
||||
'deleted' => array(
|
||||
'type' => NotificationInterface::SUCCESS,
|
||||
'message' => 'The resource was deleted',
|
||||
),
|
||||
), isset($config['presets']) ? $config['presets'] : array());
|
||||
|
||||
return $config; // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $config
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function normalizeFlashBagConfig($config)
|
||||
{
|
||||
if (null === $config || false === $config) {
|
||||
return array('enabled' => false);
|
||||
}
|
||||
|
||||
if (!\is_array($config) || !\array_key_exists('mapping', $config) || !\is_array($config['mapping'])) {
|
||||
return array('enabled' => true);
|
||||
}
|
||||
|
||||
$mapping = $config['mapping'];
|
||||
|
||||
foreach ($mapping as $key => $values) {
|
||||
if (!\is_string($key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!\is_array($values)) {
|
||||
$mapping[$key] = array($values);
|
||||
}
|
||||
|
||||
foreach ($mapping[$key] as $index => $value) {
|
||||
if (!\is_string($value)) {
|
||||
unset($mapping[$key][$index]);
|
||||
}
|
||||
}
|
||||
|
||||
$mapping[$key] = array_values($mapping[$key]);
|
||||
}
|
||||
|
||||
return array(
|
||||
'enabled' => true,
|
||||
'mapping' => $mapping,
|
||||
);
|
||||
}
|
||||
}
|
158
vendor/php-flasher/flasher/Plugin/Plugin.php
vendored
Normal file
158
vendor/php-flasher/flasher/Plugin/Plugin.php
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the PHPFlasher package.
|
||||
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Flasher\Prime\Plugin;
|
||||
|
||||
abstract class Plugin implements PluginInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
$alias = basename(str_replace('\\', '/', \get_class($this)));
|
||||
$alias = str_replace('Plugin', '', $alias);
|
||||
/** @var string $alias */
|
||||
$alias = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $alias);
|
||||
|
||||
return strtolower($alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'flasher_'.$this->getAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getServiceID()
|
||||
{
|
||||
return 'flasher.'.$this->getAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFactory()
|
||||
{
|
||||
return str_replace('Plugin', 'Factory', \get_class($this)); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getScripts()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStyles()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAssetsDir()
|
||||
{
|
||||
$resourcesDir = $this->getResourcesDir();
|
||||
$assetsDir = rtrim($resourcesDir, '/').'/assets/';
|
||||
|
||||
return realpath($assetsDir) ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResourcesDir()
|
||||
{
|
||||
$r = new \ReflectionClass($this);
|
||||
$fileName = pathinfo($r->getFileName() ?: '', PATHINFO_DIRNAME).'/Resources/';
|
||||
|
||||
return realpath($fileName) ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{
|
||||
* scripts?: string|string[]|array{cdn?: string|string[], local?: string|string[]},
|
||||
* styles?: string|string[]|array{cdn?: string|string[], local?: string|string[]},
|
||||
* options?: array<string, mixed>,
|
||||
* } $config
|
||||
*
|
||||
* @return array{
|
||||
* scripts: array{cdn: string[], local: string[]},
|
||||
* styles: array{cdn: string[], local: string[]},
|
||||
* options: array<string, mixed>,
|
||||
* }
|
||||
*/
|
||||
public function normalizeConfig(array $config)
|
||||
{
|
||||
$config = $this->processConfiguration($config);
|
||||
|
||||
$config['styles'] = $this->normalizeAssets($config['styles']);
|
||||
$config['scripts'] = $this->normalizeAssets($config['scripts']);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{
|
||||
* scripts?: string|string[]|array{cdn?: string|string[], local?: string|string[]},
|
||||
* styles?: string|string[]|array{cdn?: string|string[], local?: string|string[]},
|
||||
* options?: array<string, mixed>,
|
||||
* } $options
|
||||
*
|
||||
* @return array{
|
||||
* scripts: string|string[]|array{cdn?: string|string[], local?: string|string[]},
|
||||
* styles: string|string[]|array{cdn?: string|string[], local?: string|string[]},
|
||||
* options: array<string, mixed>,
|
||||
* }
|
||||
*/
|
||||
public function processConfiguration(array $options = array())
|
||||
{
|
||||
return array_merge(array(
|
||||
'scripts' => $this->getScripts(),
|
||||
'styles' => $this->getStyles(),
|
||||
'options' => $this->getOptions(),
|
||||
), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array{cdn?: string|string[], local?: string|string[]} $assets
|
||||
*
|
||||
* @return array{cdn: string[], local: string[]}
|
||||
*/
|
||||
protected function normalizeAssets($assets = array())
|
||||
{
|
||||
if (is_string($assets)) {
|
||||
$assets = array('cdn' => $assets, 'local' => $assets);
|
||||
}
|
||||
|
||||
$assets = array_merge(array('cdn' => null, 'local' => null), $assets);
|
||||
|
||||
$assets['cdn'] = (array) $assets['cdn'];
|
||||
$assets['local'] = (array) $assets['local'];
|
||||
|
||||
return $assets;
|
||||
}
|
||||
}
|
80
vendor/php-flasher/flasher/Plugin/PluginInterface.php
vendored
Normal file
80
vendor/php-flasher/flasher/Plugin/PluginInterface.php
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the PHPFlasher package.
|
||||
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Flasher\Prime\Plugin;
|
||||
|
||||
use Flasher\Prime\Factory\NotificationFactoryInterface;
|
||||
|
||||
interface PluginInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAlias();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceID();
|
||||
|
||||
/**
|
||||
* @return class-string<NotificationFactoryInterface>
|
||||
*/
|
||||
public function getFactory();
|
||||
|
||||
/**
|
||||
* @return string|string[]|array{cdn?: string|string[], local?: string|string[]}
|
||||
*/
|
||||
public function getScripts();
|
||||
|
||||
/**
|
||||
* @return string|string[]|array{cdn?: string|string[], local?: string|string[]}
|
||||
*/
|
||||
public function getStyles();
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getOptions();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAssetsDir();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResourcesDir();
|
||||
|
||||
/**
|
||||
* @phpstan-param array{
|
||||
* scripts?: string|array,
|
||||
* styles?: string|array,
|
||||
* options?: array,
|
||||
* } $config
|
||||
*
|
||||
* @phpstan-return array{
|
||||
* scripts?: array,
|
||||
* styles?: array,
|
||||
* options?: array,
|
||||
* }
|
||||
*/
|
||||
public function normalizeConfig(array $config);
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function processConfiguration(array $options = array());
|
||||
}
|
Reference in New Issue
Block a user