deprecate Dispatcher@runPreFilters, runEvent, runPostFilters and filter.

Now filters are handled by each FilteredCallable.
dispatcher-rework
fadrian06 3 days ago
parent 80705ec158
commit b0203d861c

@ -106,9 +106,10 @@ class Dispatcher
} }
/** /**
* @param array<int, mixed> &$params * @deprecated Don't override this method.
* * @param string $eventName Callable name.
* @throws Exception * @param mixed[] &$params Callable input.
* @throws Throwable If any of the callable filters throw an `Throwable`.
*/ */
protected function runPreFilters(string $eventName, array &$params): self protected function runPreFilters(string $eventName, array &$params): self
{ {
@ -122,9 +123,10 @@ class Dispatcher
} }
/** /**
* @param array<int, mixed> &$params * @deprecated Don't override this method.
* * @param string $eventName Callable name.
* @return void|mixed * @param mixed[] &$params Callable input.
* @return void|never|mixed
* @throws Throwable If the callable or its filters throw an `Throwable`. * @throws Throwable If the callable or its filters throw an `Throwable`.
* @throws OutOfBoundsException If callable name is not found. * @throws OutOfBoundsException If callable name is not found.
*/ */
@ -140,10 +142,11 @@ class Dispatcher
} }
/** /**
* @param mixed &$output * @deprecated Don't override this method.
* * @template Output of mixed
* @return mixed * @param Output &$output Callable output.
* @throws Exception * @return Output Callable output.
* @throws Throwable If any of the callable filters throw an `Throwable`.
*/ */
protected function runPostFilters(string $eventName, &$output) protected function runPostFilters(string $eventName, &$output)
{ {
@ -258,23 +261,23 @@ class Dispatcher
} }
/** /**
* Executes a chain of method filters. * Executes a list of callable filters.
* *
* @param array<int, callable(array<int, mixed> &$params, mixed &$output): (void|false)> $filters * @deprecated This method will be removed.
* Chain of filters. * @param (callable(mixed[] &$params, mixed &$output): (void|never|false))[] $filters Callable filters.
* @param array<int, mixed> $params Method parameters. * @param mixed[] $params Callable input.
* @param mixed $output Method output. * @param mixed $output Callable output.
* * @throws Throwable If any of the callable filters throw an `Throwable`.
* @throws Exception If an event throws an `Exception` or if `$filters` contains an invalid filter. * @throws InvalidArgumentException If any of the callable filters is not a `callable`.
*/ */
public function filter(array $filters, array &$params, &$output): void public function filter(array $filters, array &$params, &$output): void
{ {
foreach ($filters as $key => $callback) { foreach ($filters as $key => $filter) {
if (!is_callable($callback)) { if (!is_callable($filter)) {
throw new InvalidArgumentException("Invalid callable \$filters[$key]."); throw new InvalidArgumentException("Invalid callable \$filters[$key].");
} }
$continue = $callback($params, $output); $continue = $filter($params, $output);
if ($continue === false) { if ($continue === false) {
break; break;

Loading…
Cancel
Save