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
throw exception if present does not exists
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
namespace Flasher\Prime\EventDispatcher\EventListener;
|
||||
|
||||
use Flasher\Prime\EventDispatcher\Event\PersistEvent;
|
||||
use Flasher\Prime\Exception\PresetNotFoundException;
|
||||
use Flasher\Prime\Notification\Envelope;
|
||||
use Flasher\Prime\Stamp\PresetStamp;
|
||||
|
||||
@@ -21,7 +22,7 @@ use Flasher\Prime\Stamp\PresetStamp;
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
class PresetListener implements EventSubscriberInterface
|
||||
final class PresetListener implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @phpstan-var PresetType[]
|
||||
@@ -65,7 +66,7 @@ class PresetListener implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
if (!isset($this->presets[$preset->getPreset()])) {
|
||||
return;
|
||||
throw new PresetNotFoundException($preset->getPreset(), array_keys($this->presets));
|
||||
}
|
||||
|
||||
$preset = $this->presets[$preset->getPreset()];
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the PHPFlasher package.
|
||||
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Flasher\Prime\Exception;
|
||||
|
||||
final class PresetNotFoundException extends \Exception
|
||||
{
|
||||
/**
|
||||
* @param string $preset
|
||||
* @param string[] $availablePresets
|
||||
*/
|
||||
public function __construct($preset, array $availablePresets = array())
|
||||
{
|
||||
$message = sprintf('Preset "%s" not found, did you forget to register it?', $preset);
|
||||
if (array() !== $availablePresets) {
|
||||
$message .= sprintf(' Available presets: %s', implode(', ', $availablePresets));
|
||||
}
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user