Download the PHP package sroze/argument-resolver without Composer
On this page you can find all versions of the php package sroze/argument-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sroze/argument-resolver
More information about sroze/argument-resolver
Files in sroze/argument-resolver
Package argument-resolver
Short Description A lightweight utility to resolve method arguments based on types and names
License MIT
Homepage https://github.com/sroze/ArgumentResolver
Informations about the package argument-resolver
Argument Resolver
This lightweight library helps to automatically call a callable (function, method or closure) with a list of available arguments. The developer of the callable can then use type hinting and/or specific variable names to chose which arguments (s)he wants.
Installation
The suggested installation method is via composer:
Resolving arguments
The argument resolver can be created easily using the ArgumentResolverFactory
class:
The resolveArguments
method returns an ordered array of resolved arguments for the given callable. The method's arguments
are:
- The callable
- The available arguments, as an array
Here's an example of how it can be used to have arguments of some closures based on a set of available arguments:
More than argument identification with type hinting, you can also use names:
To prevent possible conflicts, the library follow priorities and constraints described in the Rules chapter.
The callable runner
Because when you've resolved the needed arguments of a given callable it's often to call it, the library comes with a
CallableRunner
class that will do everything for you:
Instantiate an object
Sometimes, you would like to instantiate an object with a set of arguments. Here's the Instanciator
usage:
Rules
Priorities
These are the resolution priorities for the arguments:
- Strict matching: Same name and same type
- Type matching
- Name matching
Constraints
The following constraints applies:
- If there's multiple arguments of the same type, then strict matching apply for this type
- Required arguments have to be resolved