You've already forked php-flasher
mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-04-05 12:32:55 +01:00
remove lumen support and clean up service provider
This commit is contained in:
@@ -10,28 +10,47 @@ use Illuminate\Foundation\Application;
|
||||
|
||||
class Laravel implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @param Container $app
|
||||
*/
|
||||
public function __construct(Container $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function shouldBeUsed()
|
||||
{
|
||||
return $this->app instanceof Application;
|
||||
}
|
||||
|
||||
public function publishConfig(FlasherToastrServiceProvider $provider)
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function boot(FlasherToastrServiceProvider $provider)
|
||||
{
|
||||
$source = realpath($raw = flasher_path(__DIR__.'/../../Resources/config/config.php')) ?: $raw;
|
||||
|
||||
$provider->publishes(array($source => config_path('flasher_toastr.php')), 'config');
|
||||
|
||||
$provider->mergeConfigFrom($source, 'flasher_toastr');
|
||||
$provider->publishes(array(flasher_path(__DIR__.'/../../Resources/config/config.php') => config_path('flasher_toastr.php')), 'config');
|
||||
}
|
||||
|
||||
public function registerToastrServices()
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function register(FlasherToastrServiceProvider $provider)
|
||||
{
|
||||
$provider->mergeConfigFrom(flasher_path(__DIR__.'/../../Resources/config/config.php'), 'flasher_toastr');
|
||||
$this->appendToFlasherConfig();
|
||||
|
||||
$this->registerServices();
|
||||
}
|
||||
|
||||
public function registerServices()
|
||||
{
|
||||
$this->app->singleton('flasher.toastr', function (Container $app) {
|
||||
return new ToastrFactory($app['flasher.storage_manager']);
|
||||
@@ -46,7 +65,7 @@ class Laravel implements ServiceProviderInterface
|
||||
});
|
||||
}
|
||||
|
||||
public function mergeConfigFromToastr()
|
||||
public function appendToFlasherConfig()
|
||||
{
|
||||
$flasherConfig = $this->app['config']->get('flasher.adapters.toastr', array());
|
||||
|
||||
|
||||
@@ -7,17 +7,32 @@ use Illuminate\Foundation\Application;
|
||||
|
||||
final class Laravel4 extends Laravel
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function shouldBeUsed()
|
||||
{
|
||||
return $this->app instanceof Application && 0 === strpos(Application::VERSION, '4.');
|
||||
}
|
||||
|
||||
public function publishConfig(FlasherToastrServiceProvider $provider)
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function boot(FlasherToastrServiceProvider $provider)
|
||||
{
|
||||
$provider->package('php-flasher/flasher-toastr-laravel', 'flasher_toastr', flasher_path(__DIR__.'/../../Resources'));
|
||||
$this->appendToFlasherConfig();
|
||||
}
|
||||
|
||||
public function mergeConfigFromToastr()
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function register(FlasherToastrServiceProvider $provider)
|
||||
{
|
||||
$this->registerServices();
|
||||
}
|
||||
|
||||
public function appendToFlasherConfig()
|
||||
{
|
||||
$flasherConfig = $this->app['config']->get('flasher::config.adapters.toastr', array());
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Laravel\ServiceProvider\Providers;
|
||||
|
||||
use Flasher\Toastr\Laravel\FlasherToastrServiceProvider;
|
||||
use Laravel\Lumen\Application;
|
||||
|
||||
final class Lumen extends Laravel
|
||||
{
|
||||
public function shouldBeUsed()
|
||||
{
|
||||
return $this->app instanceof Application;
|
||||
}
|
||||
|
||||
public function publishConfig(FlasherToastrServiceProvider $provider)
|
||||
{
|
||||
$source = realpath($raw = flasher_path(__DIR__.'/../../Resources/config/config.php')) ?: $raw;
|
||||
|
||||
$this->app->configure('flasher_toastr');
|
||||
|
||||
$provider->mergeConfigFrom($source, 'flasher_toastr');
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,18 @@ use Flasher\Toastr\Laravel\FlasherToastrServiceProvider;
|
||||
|
||||
interface ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldBeUsed();
|
||||
|
||||
public function publishConfig(FlasherToastrServiceProvider $provider);
|
||||
/**
|
||||
* @param FlasherToastrServiceProvider $provider
|
||||
*/
|
||||
public function boot(FlasherToastrServiceProvider $provider);
|
||||
|
||||
public function registerToastrServices();
|
||||
|
||||
public function mergeConfigFromToastr();
|
||||
/**
|
||||
* @param FlasherToastrServiceProvider $provider
|
||||
*/
|
||||
public function register(FlasherToastrServiceProvider $provider);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ use Flasher\Toastr\Laravel\ServiceProvider\Providers\ServiceProviderInterface;
|
||||
|
||||
final class ServiceProviderManager
|
||||
{
|
||||
/**
|
||||
* @var ServiceProviderInterface
|
||||
*/
|
||||
private $provider;
|
||||
|
||||
/**
|
||||
@@ -15,11 +18,16 @@ final class ServiceProviderManager
|
||||
private $providers = array(
|
||||
'Flasher\Toastr\Laravel\ServiceProvider\Providers\Laravel4',
|
||||
'Flasher\Toastr\Laravel\ServiceProvider\Providers\Laravel',
|
||||
'Flasher\Toastr\Laravel\ServiceProvider\Providers\Lumen',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var FlasherToastrServiceProvider
|
||||
*/
|
||||
private $notifyServiceProvider;
|
||||
|
||||
/**
|
||||
* @param FlasherToastrServiceProvider $notifyServiceProvider
|
||||
*/
|
||||
public function __construct(FlasherToastrServiceProvider $notifyServiceProvider)
|
||||
{
|
||||
$this->notifyServiceProvider = $notifyServiceProvider;
|
||||
@@ -28,15 +36,13 @@ final class ServiceProviderManager
|
||||
public function boot()
|
||||
{
|
||||
$provider = $this->resolveServiceProvider();
|
||||
|
||||
$provider->publishConfig($this->notifyServiceProvider);
|
||||
$provider->mergeConfigFromToastr();
|
||||
$provider->boot($this->notifyServiceProvider);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
$provider = $this->resolveServiceProvider();
|
||||
$provider->registerToastrServices();
|
||||
$provider->register($this->notifyServiceProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,57 +23,55 @@ class FlasherToastrServiceProviderTest extends TestCase
|
||||
$config = $this->app->make('flasher.config');
|
||||
|
||||
$expected = array(
|
||||
'toastr' => 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',
|
||||
),
|
||||
'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',
|
||||
'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',
|
||||
),
|
||||
'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',
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $config->get('adapters'));
|
||||
$this->assertEquals($expected, $config->get('adapters.toastr'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user