Download the PHP package saschati/yii2-value-object without Composer
On this page you can find all versions of the php package saschati/yii2-value-object. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download saschati/yii2-value-object
More information about saschati/yii2-value-object
Files in saschati/yii2-value-object
Package yii2-value-object
Short Description This extension will help you work with your fields in the database as objects by distilling them from scalar values into objects and vice versa.
License MIT
Informations about the package yii2-value-object
Yii2 Value Object
This extension will help you work with your fields in the database as objects, selecting them from scalar values in objects and vice versa. Also you will be able to make flat types for on type json and in an array and to convert such scalar data as tinyint in bool.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Usage
You just need to connect one of the behavior variations to your ActiveRecord model
Mapping of properties takes place with the help of handlers that process them, documentation about available handlers is how to create a custom:
- Value Object data types, using ValueObjectHandler
- Flat data types, using FlatTypeHandler
- Embedded data types, using EmbeddedHandler
- Mapped attribute, using MapperHandler
- Create instance via constructor, using ConstructorHandler
- Create instance via Yii::create, using YiiCreateHandler
- Each item, using EachHandler
-
Custom handler, using AbstractHandler or HandlerInterface
Property/Virtual Attribute/DB Attribute
Also, mapping has several features for defining properties, such as:
@property
- "@" always indicates that the property with which we interact must be an attribute, that is, we map to the attribute and map from the attribute.#buildOrVirtualProperty
- "#" this prefix points to a non-existent property in the object, which is a simple intermediate build and will simply be stored in a separate location.property
- This indicates that the property is available in the entity class, that is, if you declare such a property directly in the class, the library will interact with it.
Example:
This mapping works according to the principle:
- After Find - from right to left, top to bottom.
-
Before Save - from left to right, bottom to top.
Nested properties
One of the features of the library is that it can work with nested properties, arrays of objects and arrays of objects.
Example:
contact
column in DB
mapping
If you define these properties for handlers that can process them independently, then the library itself will store the data in the place from where it received it during extraction. But at the moment there is a list of handlers that do not support the reverse property mapper, this:
- ConstructorHandler
- YiiCreateHandler
For these handlers, you need to define a resolver that accepts a handler with extensions of an AbstractHandler that, in turn, can work with these attributes.
Example with implementation above:
And then the library itself will break it down into keys or properties and find the necessary nested property that needs to be changed.
All versions of yii2-value-object with dependencies
yiisoft/yii2 Version ^2.0.0
ramsey/uuid Version ^4.0
webmozart/assert Version ^1.8.0
marc-mabe/php-enum Version ^4.7.0
ramsey/collection Version ^1.3