v3.0.3
Added support for dependency injection and optional use of the PHP's __invoke
method, so you don't have to specify a method name as a second argument when using classes as callbacks.
Dependency injection on route classes
When using classes to handle your route callback, and those classes have some dependencies that need to be injected
through a constructor, you can specify them as an array of arguments to be injected or
let the library try to auto-inject classes.
$routes->add(
'/demo',
[
HomeController::class,
'dependency_injection_test',
[ new InjectedClass() ]
],
Routes::GET
);
You can also use named arguments or mix and match them
$routes->add(
'/demo',
[
HomeController::class,
'dependency_injection_test',
[ "injected_var" => new InjectedClass(), new Middleware ]
],
Routes::GET
);
Letting the library auto-inject classes into the constructor
$routes->add(
'/demo',
[ InjectController::class ],
Routes::GET
);
NOTE
The library will always try to auto-inject classes (will skip ones with null as default value) if non are
provided, and you're using a class for callbacks.