Download the PHP package c01l/phpdecorator without Composer
On this page you can find all versions of the php package c01l/phpdecorator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download c01l/phpdecorator
More information about c01l/phpdecorator
Files in c01l/phpdecorator
Package phpdecorator
Short Description The phpdecorator library can be used to wrap functions of objects and classes with additional functionality. This is a feature that can be compared to Python decorators.
License MIT
Informations about the package phpdecorator
phpdecorator
The phpdecorator library can be used to wrap functions of objects and classes with additional functionality. This is a feature that can be compared to Python decorators.
How to create your own decorators?
- Declare an attribute that can be put on methods extending the Decorator base-class provided by the library.
- Implement the wrap function returning a function that will be called instead of the original function.
- Use
call_user_func_array
together withfunc_get_args
to call the original function.
Using decorators
Just annotate the relevant function on a class.
The functionality will only be replaced if the object is passed through the library:
Advanced Usage
Passing a container for dependencies to the decorators
You can supply a container to the DecoratorManager
which will passed on to each Decorator
that will be instantiated.
In the decorator you can fetch the container with $this->getContainer()
.
Caching the generated classes
If you are using this library on a large amount of classes, it might be suitable to use the class cache. Then classes are generated once and can be optimized by the runtime.
Just supply a path to a folder where your runtime is allowed to read and write files.