Download the PHP package alevikzs/phmap without Composer
On this page you can find all versions of the php package alevikzs/phmap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alevikzs/phmap
More information about alevikzs/phmap
Files in alevikzs/phmap
Package phmap
Short Description Library provide mapping some php structures (json string, array, object) to specific object. This library based on Phalcon annotations.
License MIT
Informations about the package phmap
PhMap
About
The PhMap is a PHP package for create objects from JSON strings, associative arrays and objects. The PhMap is based on phalcon annotations.
Requirements
- PHP >= 5.4 && < 7.0;
- Phalcon framework >= 2.0;
- If you will be using APC or XCache adapters you need to install corresponding PHP extensions.
Installation
- Require the package and its dependencies with composer:
- Install Phalcon framework. Detail guide is here.
How to use
As you can see, if some property of you object has type of another class - you must declare an annotation
for setter method of this property. This annotation has two arguments: and . The first
argument is a string with the class name and second is a boolean value that indicates your property value is
array or not.
Create object of Tree class from JSON string:
Create object of Tree class from associative array:
Create object of Tree class from another object:
You can use if you don't know what type of you value. In this case mapping instructions will be applied automatically:
By default mapper use memory adapter, but also you can use file adapter, APC adapter and XCache adapter:
Also, you can pass already exist object to constructor:
You can reuse mapper object. Just set the necessary properties, and call the method :
Mapper object has method. The argument of this method is a transforms object. This object is used to declare a set of rules where each rule indicates what field of input value corresponds to the output field value:
For skipping some attributes and not map them, you can use :
If you want to disable validation you can use method:
If you want your class can map some value to itself you must use MapperTrait in your class declaration:
and then you can call or methods:
The MIT License (MIT)
Copyright (c) 2016 Alexey Novikov [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All versions of phmap with dependencies
ext-phalcon Version 2.0.*