Download the PHP package darkghosthunter/fluid without Composer
On this page you can find all versions of the php package darkghosthunter/fluid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download darkghosthunter/fluid
More information about darkghosthunter/fluid
Files in darkghosthunter/fluid
Package fluid
Short Description Fluid utility class based on Laravel's Fluent class
License MIT
Informations about the package fluid
Fluid
A flexible class based on the famous Laravel's Fluent and Eloquent Model class.
Fluid will allow you to flexible manipulate a class as a bag of properties (or array keys), and allow simple serialization while hiding sensible data from your users.
Installation
Fire up composer and require it into your project.
Otherwise, you can just download this as a ZIP file and require it manually in your code:
Usage
The Fluid class is a class that can be accessed as a normal object or array. It can be serialized to an array, string or JSON.
You can instance Fluid like the normal way, or just using make()
:
You can also use fromJson()
if you need to make an instance from a JSON string:
To be totally safe to use, these static helper methods will return your class that extended the Fluid
instead of the base class. So using Oil::make()
will return an instance of Oil
.
Override the static helpers
Fluid uses the magic of __callStatic
to create a new instance. In previous versions you could not override the static methods with your own logic, but now you can:
Attributes
Every attribute lies inside a protected array called $attributes
, and each of these can be set as it was a property or an array.
For convenience, if a property or array key doesn't exists it will return null.
Serializing
Serializing means taking the class to another representation, like an array or string.
To serialize as an array, use the toArray()
method.
Since there is no magic for using
(array)$fluid
, the latter will serialize every property, so to avoid that.
Serializing to a string will output JSON, as with the toJson()
method.
Hiding attributes from serialization
Sometimes is handy to hide attributes from serialization, like application keys, API secrets, user credentials or certificate locations.
You can turn this on using shouldHide()
method, or if you're extending Fluid
, setting $shouldHide
to false.
Set the attributes to hide inside the $hidden
property. Alternatively, you can use the setHidden()
method after is instanced.
Fillable
Sometimes you want to ensure the user doesn't fill anything more than some predetermined attributes. You can use the FluidFillable
class to enforce this.
You can put the attributes allowed to be set in the $fillable
array or use setFillable()
afterwards.
The user will get a InvalidAttributeException
when trying to set an attribute which is not fillable in the class.
You can use this to force developers to only allow certain attributes inside an instance, allowing you to displace any filtering logic once the instance is processed in your application.
License
This package is licenced by the MIT License.
All versions of fluid with dependencies
ext-json Version *