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
Merge pull request #18 from php-flasher/feat/phpstan-prime
feat/phpstan prime
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
parameters:
|
||||
paths:
|
||||
- src/Prime
|
||||
- src/Laravel
|
||||
level: 8
|
||||
excludes_analyse:
|
||||
- vendor/*
|
||||
|
||||
@@ -7,10 +7,15 @@ use Illuminate\Config\Repository;
|
||||
|
||||
final class Config implements ConfigInterface
|
||||
{
|
||||
/** @var Repository */
|
||||
private $config;
|
||||
|
||||
/** @var string */
|
||||
private $separator;
|
||||
|
||||
/**
|
||||
* @param string $separator
|
||||
*/
|
||||
public function __construct(Repository $config, $separator = '.')
|
||||
{
|
||||
$this->config = $config;
|
||||
@@ -22,6 +27,13 @@ final class Config implements ConfigInterface
|
||||
return $this->getFrom('flasher', $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $namespace
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFrom($namespace, $key, $default = null)
|
||||
{
|
||||
return $this->config->get($namespace . $this->separator . $key, $default);
|
||||
|
||||
@@ -3,16 +3,21 @@
|
||||
namespace Flasher\Laravel;
|
||||
|
||||
use Flasher\Laravel\ServiceProvider\ServiceProviderManager;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
final class FlasherServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$manager = new ServiceProviderManager($this);
|
||||
/** @var Container $app */
|
||||
$app = $this->app;
|
||||
$manager = new ServiceProviderManager($this, $app);
|
||||
$manager->boot();
|
||||
}
|
||||
|
||||
@@ -21,7 +26,9 @@ final class FlasherServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$manager = new ServiceProviderManager($this);
|
||||
/** @var Container $app */
|
||||
$app = $this->app;
|
||||
$manager = new ServiceProviderManager($this, $app);
|
||||
$manager->register();
|
||||
}
|
||||
|
||||
@@ -38,11 +45,14 @@ final class FlasherServiceProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Container\Container
|
||||
* @return Container
|
||||
*/
|
||||
public function getApplication()
|
||||
{
|
||||
return $this->app;
|
||||
/** @var Container $app */
|
||||
$app = $this->app;
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
public function mergeConfigFrom($path, $key)
|
||||
@@ -50,6 +60,9 @@ final class FlasherServiceProvider extends ServiceProvider
|
||||
parent::mergeConfigFrom($path, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $paths
|
||||
*/
|
||||
public function publishes(array $paths, $groups = null)
|
||||
{
|
||||
parent::publishes($paths, $groups);
|
||||
@@ -60,6 +73,9 @@ final class FlasherServiceProvider extends ServiceProvider
|
||||
parent::loadTranslationsFrom($path, $namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function loadViewsFrom($path, $namespace)
|
||||
{
|
||||
parent::loadViewsFrom($path, $namespace);
|
||||
|
||||
@@ -69,7 +69,11 @@ final class SessionMiddleware
|
||||
}
|
||||
|
||||
$content = $response->getContent();
|
||||
$pos = strripos($content, '</body>');
|
||||
if (false === $content) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$pos = (int) strripos($content, '</body>');
|
||||
$content = substr($content, 0, $pos) . $htmlResponse . substr($content, $pos);
|
||||
$response->setContent($content);
|
||||
|
||||
@@ -77,7 +81,7 @@ final class SessionMiddleware
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function typesMapping()
|
||||
{
|
||||
@@ -93,6 +97,6 @@ final class SessionMiddleware
|
||||
}
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
return $mapping; // @phpstan-ignore-line
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Flasher\Laravel\Observer;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\FlasherInterface;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Translation\Translator;
|
||||
|
||||
final class FlasherModelObserver
|
||||
{
|
||||
@@ -33,6 +33,8 @@ final class FlasherModelObserver
|
||||
|
||||
/**
|
||||
* Handle the Model "created" event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function created(Model $model)
|
||||
{
|
||||
@@ -41,6 +43,8 @@ final class FlasherModelObserver
|
||||
|
||||
/**
|
||||
* Handle the Model "updated" event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updated(Model $model)
|
||||
{
|
||||
@@ -49,6 +53,8 @@ final class FlasherModelObserver
|
||||
|
||||
/**
|
||||
* Handle the Model "deleted" event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleted(Model $model)
|
||||
{
|
||||
@@ -57,6 +63,8 @@ final class FlasherModelObserver
|
||||
|
||||
/**
|
||||
* Handle the Model "restored" event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function restored(Model $model)
|
||||
{
|
||||
@@ -65,6 +73,8 @@ final class FlasherModelObserver
|
||||
|
||||
/**
|
||||
* Handle the Model "force deleted" event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function forceDeleted(Model $model)
|
||||
{
|
||||
@@ -73,15 +83,17 @@ final class FlasherModelObserver
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addFlash($method, Model $model)
|
||||
{
|
||||
$exludes = $this->config->get('observer_events.exclude', array());
|
||||
if (in_array($method, $exludes, true)) {
|
||||
$excludes = $this->config->get('observer_events.exclude', array());
|
||||
if (in_array($method, $excludes, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($exludes[$method]) && in_array(get_class($model), $exludes[$method], true)) {
|
||||
if (isset($excludes[$method]) && in_array(get_class($model), $excludes[$method], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,7 +101,14 @@ final class FlasherModelObserver
|
||||
$message = $this->translator->get(sprintf('flasher::messages.flashable.%s.%s', get_class($model), $method));
|
||||
} else {
|
||||
$message = $this->translator->get(sprintf('flasher::messages.flashable.default.%s', $method));
|
||||
$message = str_replace('{{ model }}', substr(strrchr(get_class($model), '\\'), 1), $message);
|
||||
$replace = strrchr(get_class($model), '\\');
|
||||
if (false !== $replace) {
|
||||
$message = str_replace('{{ model }}', substr($replace, 1), $message);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->flasher->addSuccess($message);
|
||||
|
||||
@@ -1,31 +1,44 @@
|
||||
<?php
|
||||
switch ($envelope->getType()) {
|
||||
case 'success':
|
||||
$title = 'Success';
|
||||
$alertClass = 'alert-success';
|
||||
$progressBackgroundColor = '#155724';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Success:"><use xlink:href="#check-circle-fill"/></svg>';
|
||||
break;
|
||||
case 'error':
|
||||
$title = 'Error';
|
||||
$alertClass = 'alert-danger';
|
||||
$progressBackgroundColor = '#721c24';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Danger:"><use xlink:href="#exclamation-triangle-fill"/></svg>';
|
||||
break;
|
||||
case 'warning':
|
||||
$title = 'Warning';
|
||||
$alertClass = 'alert-warning';
|
||||
$progressBackgroundColor = '#856404';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Warning:"><use xlink:href="#exclamation-triangle-fill"/></svg>';
|
||||
break;
|
||||
case 'info':
|
||||
default:
|
||||
$title = 'Info';
|
||||
$alertClass = 'alert-info';
|
||||
$progressBackgroundColor = '#0c5460';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Info:"><use xlink:href="#info-fill"/></svg>';
|
||||
break;
|
||||
}
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Notification\Template;
|
||||
|
||||
if (!isset($envelope) || !$envelope instanceof Envelope) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification = $envelope->getNotification();
|
||||
if (!$notification instanceof Template) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($notification->getType()) {
|
||||
case 'success':
|
||||
$title = 'Success';
|
||||
$alertClass = 'alert-success';
|
||||
$progressBackgroundColor = '#155724';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Success:"><use xlink:href="#check-circle-fill"/></svg>';
|
||||
break;
|
||||
case 'error':
|
||||
$title = 'Error';
|
||||
$alertClass = 'alert-danger';
|
||||
$progressBackgroundColor = '#721c24';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Danger:"><use xlink:href="#exclamation-triangle-fill"/></svg>';
|
||||
break;
|
||||
case 'warning':
|
||||
$title = 'Warning';
|
||||
$alertClass = 'alert-warning';
|
||||
$progressBackgroundColor = '#856404';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Warning:"><use xlink:href="#exclamation-triangle-fill"/></svg>';
|
||||
break;
|
||||
case 'info':
|
||||
default:
|
||||
$title = 'Info';
|
||||
$alertClass = 'alert-info';
|
||||
$progressBackgroundColor = '#0c5460';
|
||||
$icon = '<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Info:"><use xlink:href="#info-fill"/></svg>';
|
||||
break;
|
||||
}
|
||||
?>
|
||||
|
||||
<div style="margin-top: 0.5rem;cursor: pointer;">
|
||||
@@ -42,7 +55,7 @@
|
||||
</svg>
|
||||
<div class="alert {{ $alertClass }} text-break alert-dismissible fade in show align-items-center" role="alert" style="border-top-left-radius: 0;border-bottom-left-radius: 0;border: unset;border-left: 6px solid {{ $progressBackgroundColor }}">
|
||||
{!! $icon !!}
|
||||
<strong>{{ $envelope->getTitle() ?: $title }}</strong> {{ $envelope->getMessage() }}
|
||||
<strong>{{ $notification->getTitle() ?: $title }}</strong> {{ $notification->getMessage() }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close" onclick="this.parentElement.remove()"></button>
|
||||
</div>
|
||||
<div class="d-flex" style="height: .125rem;margin-top: -1rem;">
|
||||
|
||||
@@ -1,39 +1,52 @@
|
||||
<?php
|
||||
switch ($envelope->getType()) {
|
||||
case 'success':
|
||||
$title = 'Success';
|
||||
$textColor = 'text-green-600';
|
||||
$backgroundColor = 'bg-green-600';
|
||||
$progressBackgroundColor = 'bg-green-100';
|
||||
$borderColor = 'border-green-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="check w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>';
|
||||
break;
|
||||
case 'error':
|
||||
$title = 'Error';
|
||||
$textColor = 'text-red-600';
|
||||
$backgroundColor = 'bg-red-600';
|
||||
$progressBackgroundColor = 'bg-red-100';
|
||||
$borderColor = 'border-red-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="x w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>';
|
||||
break;
|
||||
case 'warning':
|
||||
$title = 'Warning';
|
||||
$textColor = 'text-yellow-600';
|
||||
$backgroundColor = 'bg-yellow-600';
|
||||
$progressBackgroundColor = 'bg-yellow-100';
|
||||
$borderColor = 'border-yellow-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>';
|
||||
break;
|
||||
case 'info':
|
||||
default:
|
||||
$title = 'Info';
|
||||
$textColor = 'text-blue-600';
|
||||
$backgroundColor = 'bg-blue-600';
|
||||
$progressBackgroundColor = 'bg-blue-100';
|
||||
$borderColor = 'border-blue-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation-circle w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>';
|
||||
break;
|
||||
}
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Notification\Template;
|
||||
|
||||
if (!isset($envelope) || !$envelope instanceof Envelope) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification = $envelope->getNotification();
|
||||
if (!$notification instanceof Template) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($notification->getType()) {
|
||||
case 'success':
|
||||
$title = 'Success';
|
||||
$textColor = 'text-green-600';
|
||||
$backgroundColor = 'bg-green-600';
|
||||
$progressBackgroundColor = 'bg-green-100';
|
||||
$borderColor = 'border-green-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="check w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>';
|
||||
break;
|
||||
case 'error':
|
||||
$title = 'Error';
|
||||
$textColor = 'text-red-600';
|
||||
$backgroundColor = 'bg-red-600';
|
||||
$progressBackgroundColor = 'bg-red-100';
|
||||
$borderColor = 'border-red-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="x w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>';
|
||||
break;
|
||||
case 'warning':
|
||||
$title = 'Warning';
|
||||
$textColor = 'text-yellow-600';
|
||||
$backgroundColor = 'bg-yellow-600';
|
||||
$progressBackgroundColor = 'bg-yellow-100';
|
||||
$borderColor = 'border-yellow-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>';
|
||||
break;
|
||||
case 'info':
|
||||
default:
|
||||
$title = 'Info';
|
||||
$textColor = 'text-blue-600';
|
||||
$backgroundColor = 'bg-blue-600';
|
||||
$progressBackgroundColor = 'bg-blue-100';
|
||||
$borderColor = 'border-blue-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation-circle w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>';
|
||||
break;
|
||||
}
|
||||
?>
|
||||
<div class="bg-white shadow-lg border-l-4 mt-2 cursor-pointer {{ $borderColor }}">
|
||||
<div class="flex items-center px-2 py-3 rounded-lg shadow-lg overflow-hidden">
|
||||
@@ -42,10 +55,10 @@
|
||||
</div>
|
||||
<div class="ml-4 w-0 flex-1">
|
||||
<p class="text-base leading-5 font-medium capitalize {{ $textColor }}">
|
||||
{{ $envelope->getTitle() ?: $title }}
|
||||
{{ $notification->getTitle() ?: $title }}
|
||||
</p>
|
||||
<p class="mt-1 text-sm leading-5 text-gray-500">
|
||||
{{ $envelope->getMessage() }}
|
||||
{{ $notification->getMessage() }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,39 +1,52 @@
|
||||
<?php
|
||||
switch ($envelope->getType()) {
|
||||
case 'success':
|
||||
$title = 'Success';
|
||||
$textColor = 'text-green-700';
|
||||
$backgroundColor = 'bg-green-50';
|
||||
$progressBackgroundColor = 'bg-green-200';
|
||||
$borderColor = 'border-green-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="check w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>';
|
||||
break;
|
||||
case 'error':
|
||||
$title = 'Error';
|
||||
$textColor = 'text-red-700';
|
||||
$backgroundColor = 'bg-red-50';
|
||||
$progressBackgroundColor = 'bg-red-200';
|
||||
$borderColor = 'border-red-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="x w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>';
|
||||
break;
|
||||
case 'warning':
|
||||
$title = 'Warning';
|
||||
$textColor = 'text-yellow-700';
|
||||
$backgroundColor = 'bg-yellow-50';
|
||||
$progressBackgroundColor = 'bg-yellow-200';
|
||||
$borderColor = 'border-yellow-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>';
|
||||
break;
|
||||
case 'info':
|
||||
default:
|
||||
$title = 'Info';
|
||||
$textColor = 'text-blue-700';
|
||||
$backgroundColor = 'bg-blue-50';
|
||||
$progressBackgroundColor = 'bg-blue-100';
|
||||
$borderColor = 'border-blue-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation-circle w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>';
|
||||
break;
|
||||
}
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Notification\Template;
|
||||
|
||||
if (!isset($envelope) || !$envelope instanceof Envelope) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification = $envelope->getNotification();
|
||||
if (!$notification instanceof Template) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($notification->getType()) {
|
||||
case 'success':
|
||||
$title = 'Success';
|
||||
$textColor = 'text-green-700';
|
||||
$backgroundColor = 'bg-green-50';
|
||||
$progressBackgroundColor = 'bg-green-200';
|
||||
$borderColor = 'border-green-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="check w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>';
|
||||
break;
|
||||
case 'error':
|
||||
$title = 'Error';
|
||||
$textColor = 'text-red-700';
|
||||
$backgroundColor = 'bg-red-50';
|
||||
$progressBackgroundColor = 'bg-red-200';
|
||||
$borderColor = 'border-red-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="x w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>';
|
||||
break;
|
||||
case 'warning':
|
||||
$title = 'Warning';
|
||||
$textColor = 'text-yellow-700';
|
||||
$backgroundColor = 'bg-yellow-50';
|
||||
$progressBackgroundColor = 'bg-yellow-200';
|
||||
$borderColor = 'border-yellow-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>';
|
||||
break;
|
||||
case 'info':
|
||||
default:
|
||||
$title = 'Info';
|
||||
$textColor = 'text-blue-700';
|
||||
$backgroundColor = 'bg-blue-50';
|
||||
$progressBackgroundColor = 'bg-blue-100';
|
||||
$borderColor = 'border-blue-600';
|
||||
$icon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="exclamation-circle w-5 h-5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>';
|
||||
break;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="bg-white shadow-lg border-l-4 mt-2 cursor-pointer {{ $backgroundColor }} {{ $borderColor }}">
|
||||
@@ -43,10 +56,10 @@
|
||||
</div>
|
||||
<div class="ml-4 w-0 flex-1">
|
||||
<p class="text-base leading-5 font-medium capitalize {{ $textColor }}">
|
||||
{{ $envelope->getTitle() ?: $title }}
|
||||
{{ $notification->getTitle() ?: $title }}
|
||||
</p>
|
||||
<p class="mt-1 text-sm leading-5 text-gray-500">
|
||||
{{ $envelope->getMessage() }}
|
||||
{{ $notification->getMessage() }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,6 @@ use Flasher\Prime\EventDispatcher\EventDispatcher;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\FilterListener;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\RemoveListener;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\StampsListener;
|
||||
use Flasher\Prime\Factory\NotificationFactory;
|
||||
use Flasher\Prime\Factory\TemplateFactory;
|
||||
use Flasher\Prime\Filter\Filter;
|
||||
use Flasher\Prime\Flasher;
|
||||
@@ -59,7 +58,10 @@ class Laravel implements ServiceProviderInterface
|
||||
$this->bootServices($this->app);
|
||||
}
|
||||
|
||||
protected function bootServices(Application $app)
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function bootServices(Container $app)
|
||||
{
|
||||
$templates = $app['flasher.config']->get('template_factory.templates', array());
|
||||
foreach ($templates as $template => $options) {
|
||||
@@ -91,6 +93,9 @@ class Laravel implements ServiceProviderInterface
|
||||
$this->registerCommonServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function registerCommonServices()
|
||||
{
|
||||
$this->app->singleton('flasher', function (Application $app) {
|
||||
@@ -186,6 +191,9 @@ class Laravel implements ServiceProviderInterface
|
||||
$this->app->bind('Flasher\Prime\Factory\NotificationFactoryInterface', 'flasher.template');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function registerBladeDirectives()
|
||||
{
|
||||
$startsWith = function ($haystack, $needle) {
|
||||
|
||||
@@ -17,6 +17,7 @@ final class Laravel4 extends Laravel
|
||||
|
||||
public function boot(FlasherServiceProvider $provider)
|
||||
{
|
||||
// @phpstan-ignore-next-line
|
||||
$provider->package('php-flasher/flasher-laravel', 'flasher', flasher_path(__DIR__ . '/../../Resources'));
|
||||
|
||||
$this->registerBladeDirectives();
|
||||
@@ -32,9 +33,16 @@ final class Laravel4 extends Laravel
|
||||
$this->registerCommonServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function registerBladeDirectives()
|
||||
{
|
||||
Blade::extend(function ($view, BladeCompiler $compiler) {
|
||||
if (!method_exists($compiler, 'createMatcher')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$pattern = $compiler->createMatcher('flasher_render');
|
||||
|
||||
return preg_replace($pattern, '$1<?php echo app(\'flasher.response_manager\')->render$2; ?>', $view);
|
||||
|
||||
@@ -24,6 +24,9 @@ final class Laravel50 extends Laravel
|
||||
$this->bootServices($this->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function registerBladeDirectives()
|
||||
{
|
||||
$startsWith = function ($haystack, $needle) {
|
||||
@@ -35,6 +38,10 @@ final class Laravel50 extends Laravel
|
||||
};
|
||||
|
||||
Blade::extend(function ($view, BladeCompiler $compiler) use ($startsWith, $endsWith) {
|
||||
if (!method_exists($compiler, 'createPlainMatcher')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$pattern = $compiler->createPlainMatcher('flasher_render(.*)');
|
||||
$matches = array();
|
||||
|
||||
|
||||
@@ -11,7 +11,13 @@ interface ServiceProviderInterface
|
||||
*/
|
||||
public function shouldBeUsed();
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function boot(FlasherServiceProvider $provider);
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function register(FlasherServiceProvider $provider);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ final class ResourceManagerHelper
|
||||
{
|
||||
/**
|
||||
* @param string $alias
|
||||
* @param array $config
|
||||
* @param array<string, mixed> $config
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function process(ResourceManager $responseManager, $alias, $config = null)
|
||||
{
|
||||
@@ -22,9 +24,9 @@ final class ResourceManagerHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param array<string, mixed> $config
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
private static function getScripts($config)
|
||||
{
|
||||
@@ -32,9 +34,9 @@ final class ResourceManagerHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param array<string, mixed> $config
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
private static function getStyles($config)
|
||||
{
|
||||
@@ -42,9 +44,9 @@ final class ResourceManagerHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param array<string, mixed> $config
|
||||
*
|
||||
* @return array
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private static function getOptions($config)
|
||||
{
|
||||
|
||||
@@ -3,35 +3,50 @@
|
||||
namespace Flasher\Laravel\ServiceProvider;
|
||||
|
||||
use Flasher\Laravel\FlasherServiceProvider;
|
||||
use Flasher\Laravel\ServiceProvider\Providers\Laravel;
|
||||
use Flasher\Laravel\ServiceProvider\Providers\Laravel4;
|
||||
use Flasher\Laravel\ServiceProvider\Providers\Laravel50;
|
||||
use Flasher\Laravel\ServiceProvider\Providers\Laravel51;
|
||||
use Flasher\Laravel\ServiceProvider\Providers\ServiceProviderInterface;
|
||||
use Illuminate\Container\Container;
|
||||
|
||||
final class ServiceProviderManager
|
||||
{
|
||||
/** @var ServiceProviderInterface|null */
|
||||
private $provider;
|
||||
|
||||
/**
|
||||
* @var ServiceProviderInterface[]
|
||||
*/
|
||||
private $providers = array(
|
||||
'Flasher\Laravel\ServiceProvider\Providers\Laravel4',
|
||||
'Flasher\Laravel\ServiceProvider\Providers\Laravel50',
|
||||
'Flasher\Laravel\ServiceProvider\Providers\Laravel51',
|
||||
'Flasher\Laravel\ServiceProvider\Providers\Laravel',
|
||||
);
|
||||
private $providers;
|
||||
|
||||
/** @var FlasherServiceProvider */
|
||||
private $notifyServiceProvider;
|
||||
|
||||
public function __construct(FlasherServiceProvider $notifyServiceProvider)
|
||||
public function __construct(FlasherServiceProvider $notifyServiceProvider, Container $app)
|
||||
{
|
||||
$this->notifyServiceProvider = $notifyServiceProvider;
|
||||
|
||||
$this->providers = array(
|
||||
new Laravel4($app),
|
||||
new Laravel50($app),
|
||||
new Laravel51($app),
|
||||
new Laravel($app),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$provider = $this->resolveServiceProvider();
|
||||
$provider->boot($this->notifyServiceProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$provider = $this->resolveServiceProvider();
|
||||
@@ -47,9 +62,7 @@ final class ServiceProviderManager
|
||||
return $this->provider;
|
||||
}
|
||||
|
||||
foreach ($this->providers as $providerClass) {
|
||||
$provider = new $providerClass($this->notifyServiceProvider->getApplication());
|
||||
|
||||
foreach ($this->providers as $provider) {
|
||||
if ($provider->shouldBeUsed()) {
|
||||
return $this->provider = $provider;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Flasher\Laravel\Storage;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Stamp\UuidStamp;
|
||||
use Flasher\Prime\Storage\StorageInterface;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Session\Store;
|
||||
|
||||
final class Storage implements StorageInterface
|
||||
@@ -13,12 +12,12 @@ final class Storage implements StorageInterface
|
||||
const ENVELOPES_NAMESPACE = 'flasher::envelopes';
|
||||
|
||||
/**
|
||||
* @var SessionManager|Store
|
||||
* @var Store
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @param SessionManager|Store $session
|
||||
* @param Store $session
|
||||
*/
|
||||
public function __construct($session)
|
||||
{
|
||||
@@ -44,7 +43,13 @@ final class Storage implements StorageInterface
|
||||
|
||||
$store = $this->all();
|
||||
foreach ($store as $index => $envelope) {
|
||||
$uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid();
|
||||
$uuidStamp = $envelope->get('Flasher\Prime\Stamp\UuidStamp');
|
||||
|
||||
if (!$uuidStamp instanceof UuidStamp) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$uuid = $uuidStamp->getUuid();
|
||||
|
||||
if (!isset($map[$uuid])) {
|
||||
continue;
|
||||
@@ -63,7 +68,13 @@ final class Storage implements StorageInterface
|
||||
$map = UuidStamp::indexByUuid($envelopes);
|
||||
|
||||
$store = array_filter($this->all(), function (Envelope $envelope) use ($map) {
|
||||
$uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid();
|
||||
$uuidStamp = $envelope->get('Flasher\Prime\Stamp\UuidStamp');
|
||||
|
||||
if (!$uuidStamp instanceof UuidStamp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$uuid = $uuidStamp->getUuid();
|
||||
|
||||
return !isset($map[$uuid]);
|
||||
});
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
namespace Flasher\Laravel\Template;
|
||||
|
||||
use Flasher\Prime\Template\EngineInterface;
|
||||
use Illuminate\View\Factory;
|
||||
|
||||
final class BladeEngine implements EngineInterface
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
* @var Factory
|
||||
*/
|
||||
private $engine;
|
||||
|
||||
/**
|
||||
* @param $engine
|
||||
* @param Factory $engine
|
||||
*/
|
||||
public function __construct($engine)
|
||||
{
|
||||
@@ -21,6 +22,8 @@ final class BladeEngine implements EngineInterface
|
||||
|
||||
public function render($name, array $context = array())
|
||||
{
|
||||
return (string) $this->engine->make($name, $context);
|
||||
$view = $this->engine->make($name, $context);
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Flasher\Prime\FlasherInterface;
|
||||
use Flasher\Prime\Stamp\StampInterface;
|
||||
|
||||
if (!function_exists('flash')) {
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $type
|
||||
* @param array<string, mixed> $options
|
||||
* @param StampInterface[] $stamps
|
||||
*
|
||||
* @return \Flasher\Prime\Flasher
|
||||
* @return FlasherInterface
|
||||
*/
|
||||
function flash($message = null, $type = 'success', array $options = array(), array $stamps = array())
|
||||
{
|
||||
/** @var \Flasher\Prime\FlasherInterface $flasher */
|
||||
$flasher = app('flasher');
|
||||
|
||||
if (null === $message && 0 === func_num_args()) {
|
||||
@@ -24,8 +28,10 @@ if (!function_exists('flasher')) {
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $type
|
||||
* @param array<string, mixed> $options
|
||||
* @param StampInterface[] $stamps
|
||||
*
|
||||
* @return \Flasher\Prime\Flasher
|
||||
* @return FlasherInterface
|
||||
*/
|
||||
function flasher($message = null, $type = 'success', array $options = array(), array $stamps = array())
|
||||
{
|
||||
|
||||
@@ -4,8 +4,12 @@ namespace Flasher\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Factory\NotificationFactoryInterface;
|
||||
use Flasher\Prime\Notification\NotificationBuilderInterface;
|
||||
use Flasher\Prime\Response\ResponseManagerInterface;
|
||||
|
||||
/**
|
||||
* @mixin NotificationBuilderInterface
|
||||
*/
|
||||
final class Flasher implements FlasherInterface
|
||||
{
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user