Download the PHP package norvica/invoker without Composer
On this page you can find all versions of the php package norvica/invoker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package invoker
Invoker
Invoker is a lightweight PHP library that simplifies invoking functions or methods with named parameters. It's designed to flexibly resolve missing parameters, utilizing a custom resolver mechanism to provide needed arguments dynamically.
Features
- Invoke any callable (function/method) with named parameters.
- Ability to use custom resolvers for dynamic parameter resolution.
- Zero dependency, ready to integrate with your project.
Installation
Install via Composer:
Basic Usage
Here is a quick example of invoking a simple callable:
Sure, let's add some advanced examples and explanations to your readme.md
based on the dataProvider
. This will show
potential users the flexibility of your Invoker library.
Advanced Usage
The Invoker library can handle various types of callables including:
- Plain functions
- Closures
- Object instances with an
__invoke()
method - Object instances with a public method
- Static methods on a class
Here's how you can invoke these using the library:
Plain Functions
Closures
Object with __invoke
Method
Object with Public Method
Class with Static Method
Variadic Arguments
The library also supports variadic arguments. Here's how you can pass an array for a variadic parameter.
Using a Resolver
You can implement your own resolvers by adhering to the Resolver
interface, which has two methods: resolve()
and supports()
.
Example: Resolving PSR-11 Container Services
Here's how you can create a simple resolver for a PSR-11 Container:
To invoke a method with this resolver:
Example: Resolving PSR-7 Requests
A resolver can be tailored for PSR-7 ServerRequest and Response objects. Here's a sample resolver for handling
a ServerRequestInterface
.
To use it:
Of course. Adding that section would clarify the scope and philosophy of the library. Here's how you can include it in
your readme.md
:
Running Tests
Project Philosophy: Lean and Simple
The primary goal of the Invoker library is to remain as lean and straightforward as possible. The focus is on providing a core utility for invoking callables with named parameters and custom resolvers.
Out of Scope
While we appreciate suggestions and pull requests, please note that specific implementations of resolvers or extra functionalities are considered out of scope for this library. We aim to keep the codebase clean and easily maintainable, without incorporating features that may lead to bloat or complexity.
If you require more specialized behaviors, you are encouraged to extend the library or implement your own resolvers according to your project needs.
Similar Concepts and Alternatives
If you're interested in this library, you might also want to explore other similar tools and frameworks that offer functionality for argument resolution or method invocation.
Symfony Action Argument Resolving
One notable alternative is Symfony's Action Argument Resolving. This feature allows you to transform the incoming request or any other data into arguments passed into your controller methods. While it's more tightly integrated with the Symfony ecosystem, it offers a wide array of built-in resolvers and the ability to create custom ones.
PHP-DI Invoker
Another mature project with very similar idea is PHP-DI Invoker. Feel free to check the project's README.