php-di/invoker
Lightweight PHP library to call any callable with automatic dependency injection. Resolves function and method parameters by name and type-hints, integrates with PHP-DI, and supports default values for flexible invocations in frameworks, controllers, and CLI tools.
php-di/invoker is a lightweight library for resolving and invoking callables with dependency injection support. To get started:
composer require php-di/invokerInvoker\Invoker class directly, or integrate it with a container like PHP-DI, PHP-DI Bridge, or PSR-11 implementations$invoker->call($callable, $parameters) where $parameters can include named arguments, positional fallback, or container-resolved dependenciesExample first use:
$invoker = new Invoker\Invoker();
$callback = function (UserService $userService, $userId) {
return $userService->getUser($userId);
};
$result = $invoker->call($callback, [
'userId' => 123,
// UserService will be resolved automatically if container-aware or passed explicitly
]);
ContainerInterface extension)MiddlewareInterface implementations to add logging, timing, or exception handling before/after invocationResolver\ResolverInterface: Provide custom resolvers for parameters (e.g., environment-specific values, config injection)Typical workflow:
Invoker with optional PSR-11 container or resolver chain--with-external-pdo or obfuscation—always use named arrays with explicit keysInvoker is stateful but safe to reuse (especially when combined with ContainerInterface)call() can cause ambiguity; prefer explicit named arrays for maintainabilityvar_dump($invoker->getParameters($callable)) to inspect what the invoker expects to resolve before callingResolver\ResolverInterface and prepend it to the resolver chainHow can I help you explore Laravel packages today?