pine3ree / pine3ree-params-resolver
A function/method/invokable-object parameter resolution utility class
0.8.1
2025-04-27 20:57 UTC
Requires
- php: ^7.4 || ^8.0
- psr/container: ^1.1.2 || ^2.0
Requires (Dev)
- phpspec/prophecy-phpunit: ^1.1 || ^2.0
- phpstan/phpstan: ^1.10 || ^2.0
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.5.7
- webimpress/coding-standard: ^1.3
README
ParamsResolver is an utility service that uses reflection to resolve parameters for a given callable performing look-up in the following order and matched against class/interface/parameter names:
- injected parameters,
- dependencies or parameters in the injected or composed container
- default values id available in the callable
Example:
In the following example the dependency $db is fetched from the container, the
$config
parameter is provided and the $options
parameter receives the default
empty array value.
<?php use My\Db; use pine3ree\Container\ParamsResolver; class MyDataMapper { public function__construct(My\Db $db, array $config, array $options = []) { //... } //... } //... // include the container container //... $paramsResolver = new ParamsResolver($container); $args = $paramsResolver->resolve(MyDataMapper::class, '__construct', [ 'config' => [ //.. ], ]); $myDataMapper = new MyDataMapper(...args);
A common usage of ParamsResolver is within a reflection based factory