Download the PHP package phpnomad/decorator without Composer
On this page you can find all versions of the php package phpnomad/decorator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpnomad/decorator
More information about phpnomad/decorator
Files in phpnomad/decorator
Package decorator
Short Description Assists with implementing decorator patterns.
License MIT
Homepage https://github.com/phoenix/core
Informations about the package decorator
phpnomad/decorator
phpnomad/decorator is a small helper for writing decorator classes in PHP. It ships a single trait, WithDecoratedInstance, that forwards method calls to a wrapped object through __call() using an explicit allowlist, so a decorator only has to implement the behavior it actually changes.
Installation
Quick Start
Add the trait to a class that wraps another instance, assign the wrapped object, and list the methods you want forwarded.
Calls to find() or all() on a CachingRepository are forwarded to the wrapped Repository. Calls to any method that is not on $allowedMethods and is not defined on the decorator itself raise an E_USER_ERROR.
Overview
The package exports one trait, PHPNomad\Decorator\Traits\WithDecoratedInstance. Mixing it into a class adds four things.
- A
$decoratedInstanceproperty that holds the object being wrapped. - An
$allowedMethodsarray so that method forwarding is opt-in rather than automatic. - A
__call()implementation that routes allowlisted method calls to$decoratedInstanceviacall_user_func_array. - An explicit
E_USER_ERRORfor any other inaccessible method call, so typos and unintended forwards fail loudly instead of silently.
Because the allowlist is a plain array property, you control exactly which parts of the wrapped object's surface leak through the decorator.
Documentation
Broader PHPNomad framework documentation lives at phpnomad.com.
License
Released under the MIT License.