Download the PHP package ascetik/callapsule without Composer
On this page you can find all versions of the php package ascetik/callapsule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package callapsule
collabubble
A way to encapsulate a callable
Purpose
This package is made to encapsulate a callable of any type, providing the ability to handle them the same way. I needed this kind of package for routing or a service manager, any task to defer, to encapsulate callables correctly...
Release notes
v0.4.0
- CallableType abstract getReflection() method.
Usage
Use the CallWrapper factory static methods to build a CallableType :
The use of this factory is the best choice to build and use a CallableType. Some checks make direct instanciation unavailable due to private constructors.
A CallableType is able to run the callable it holds. For external needs, it is able to give its callable back as is :
CallableType methods
- CallableType::apply(?iterable): mixed : execute callable and return the result
- CallableType::action(): callable : return wrapped callable type-hinted as callable
- CallableType::getCallable(): object : return wrapped callable fully type-hinted
Implementations
I could enumerate 4 use cases for a callable wrap :
- a Closure
- a class method, with an instance and the method to run
- a static class method, with a class-string instead of an instance
- an instance with __invoke magic method
If you can find more, feel free to use CallableType abstraction.
ClosureCall
Holds a Closure. Direct instanciation (public constructor)
No Errors/Exceptions thrown
InvokableCall
Holds an invokable instance. Static factory method for checks.
Throws an UninvokableClassException if the given instance does not implement __invoke() method.
MethodCall
Holds an instance and a method. Static factory method for checks.
Throws a MethodNotImplementedException if given method is not implemented.
getCallable method returns a ClassMethod instance with a get() method returning the callable array.
StaticCall
Holds a class name and a method name. Static factory for checks.
Throws a ClassNotFoundException if given class does not exist. Throws a MethodNotImplementedException if given method is not implemented.
getCallable method returns a ClassMethod instance with a get() method returning the callable array.