Download the PHP package technically/callable-reflection without Composer
On this page you can find all versions of the php package technically/callable-reflection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download technically/callable-reflection
More information about technically/callable-reflection
Files in technically/callable-reflection
Package callable-reflection
Short Description A handy library to simplify reflecting any callable or constructor. PHP8-ready!
License MIT
Informations about the package callable-reflection
Technically Callable Reflection
Technically\CallableReflection is a handy library to simplify reflecting any callable.
It provides a unified interface for reading callable arguments seamlessly supporting PHP8 union types.
It also lets you to easily invoke a callable with call() and apply() supporting named parameters.
Features
- Unified and simplified interface to reflect callable parameters
- No dependencies
- PHP 8.2+ (including support for union types,
mixed,false, etc; see examples below) - Semver
- Tests
Installation
Use Composer package manager to add Technically\CallableReflection to your project:
Examples
Reflecting callable properties
Reflecting arbitrary class constructor
Checking if value satisfies parameter type declaration
Invoking callable via reflection
Invoking constructor via reflection
How is this better than reflecting Closure::fromCallable()
This library's functionality is somewhat similar to what a reflection of the standard Closure::fromCallable() can provide.
And if that's enough for your use case, you probably want to be using the standard reflection.
This library, however, does provide some added value on top:
-
It unifies interactions with all kinds of callables, including class constructors. That was actually the primary use case I had in mind for it — building a DI service container.
For example, you cannot instantiate a new instance with Closure::fromCallable():
but you can call a constructor with this library:
-
It provides utilities to check if a specific value satisfies the given function argument type declaration (see
->satisfies()). -
It can know and tell what type of callable was reflected, while with Closure::fromCallable() this information is lost. This might be important for certain use cases.
-
It has nice additional convenience getters and checkers. Like
satisfies(),isOptional(),isNull(),isScalar(), etc. -
The API is more intuitive and straighforward and hides away PHP version differences introduced to the Reflections API over years. The native Reflections API is polluted with BC-preserving constructs.
- The library is operating on top of the native Reflections API, and therefore is as performant as it is, plus a little overhead for the convenience wrappers.
Changelog
All notable changes to this project will be documented in the CHANGELOG file.
Credits
Implemented by :space_invader: Ivan Voskoboinyk.