Skip to content

v3.0.4

Compare
Choose a tag to compare
@gigili gigili released this 05 Jun 00:19
· 47 commits to main since this release

This is an improved version of the previous release where the support for nested dependency injection has been added and logic for dependency injection has been moved into a separate class. Some more checks have been implemented into the logic where the parameters that have default or null values, can not be instantiated or are of built in type (ex int, float, array) will be ignored.

Release notes from previous version:

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.

Full Changelog: v3.0.3...v3.0.4