throw OutOfBoundsException instead of Exception when event name hasn't been set

dispatcher-rework
fadrian06 3 days ago
parent bf3f86d619
commit bb6932e92e

@ -7,6 +7,7 @@ namespace flight\core;
use Exception; use Exception;
use flight\Engine; use flight\Engine;
use InvalidArgumentException; use InvalidArgumentException;
use OutOfBoundsException;
use Psr\Container\ContainerInterface as Container; use Psr\Container\ContainerInterface as Container;
use ReflectionFunction; use ReflectionFunction;
use Throwable; use Throwable;
@ -74,7 +75,8 @@ class Dispatcher
* @param string $name Event name. * @param string $name Event name.
* @param mixed[] $params Event callable parameters. * @param mixed[] $params Event callable parameters.
* @return mixed Output of event callable. * @return mixed Output of event callable.
* @throws Throwable If event name isn't found or if event throws an `Throwable`. * @throws Throwable If the callable or its filters throw an `Throwable`.
* @throws OutOfBoundsException If callable name is not found.
*/ */
public function run(string $name, array $params = []) public function run(string $name, array $params = [])
{ {
@ -104,14 +106,15 @@ class Dispatcher
* @param array<int, mixed> &$params * @param array<int, mixed> &$params
* *
* @return void|mixed * @return void|mixed
* @throws Exception * @throws Throwable If the callable or its filters throw an `Throwable`.
* @throws OutOfBoundsException If callable name is not found.
*/ */
protected function runEvent(string $eventName, array &$params) protected function runEvent(string $eventName, array &$params)
{ {
$requestedMethod = $this->get($eventName); $requestedMethod = $this->get($eventName);
if ($requestedMethod === null) { if ($requestedMethod === null) {
throw new Exception("Event '$eventName' isn't found."); throw new OutOfBoundsException("Event '$eventName' isn't found.");
} }
return $this->execute($requestedMethod, $params); return $this->execute($requestedMethod, $params);

Loading…
Cancel
Save