flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.6k stars 407 forks source link

Improvements to Dispatcher class #567

Closed fadrian06 closed 3 months ago

fadrian06 commented 3 months ago

Tired of declaring after filters with the first parameter without doing anything?

DELETE IT :D, nothing will be broken.

Dispatcher now supports after filters with the only useful parameter.

Flight::after('myMethod', function (&$params, &$output) {
  // $params Even if it is used it does not affect, but it had to be declared yes or yes even if it does nothing.
});

Now...

Flight::after('myMethod', function (&$output) {
  // goodbye useless $params 
});

IMPORTANT: both ways work exactly the same. Only one is shorter and cleaner.

To even make it even cleaner, you could change the filter to a PHP 7.4 arrow function.

Flight::after('myMethod', fn (&$output) => doMagic($output));

Just make sure that what you do in the arrow function doesn't return false, unless you want to make other after filters for the same mapped method not run.

n0nag0n commented 3 months ago

@fadrian06 Why'd you close the PR? It's a good PR just needs a few tweaks