Download the PHP package pushoperations/decorators without Composer
On this page you can find all versions of the php package pushoperations/decorators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pushoperations/decorators
More information about pushoperations/decorators
Files in pushoperations/decorators
Package decorators
Short Description A library of decorators.
License MIT
Homepage https://github.com/pushoperations/Decorators
Informations about the package decorators
Decorators
A library to decorate arrays (especially Laravel's Input::) for manipulation and usage as a service to return data for object construction.
Note: this library may contain other patterns in the future.
Contents
- Installation
- Usage
- Examples
- API documentation
Install
The recommended way to install is through Composer.
Update your project's composer.json file to include Decorators:
Then update the project dependencies to include this library:
After installing, you need to require Composer's autoloader:
Usage
Create your own decorator by:
- Extending from the
DataDecorator
abstract class - Creating a constructor that accepts an array
- Optional: add methods that are specific to generating the array of data you need
One use case is to split input data into different arrays for different factories to use for the construction of new objects.
A handy effect is that you can perform sanitization within the decorator's methods before returning the data array.
Examples
Common usage would be to filter and pick apart the user input for create/update: