Download the PHP package eden-tech-labs/json-2-php-class without Composer
On this page you can find all versions of the php package eden-tech-labs/json-2-php-class. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eden-tech-labs/json-2-php-class
More information about eden-tech-labs/json-2-php-class
Files in eden-tech-labs/json-2-php-class
Package json-2-php-class
Short Description Creates object of native classes from JSON string or object
License Apache-2.0
Homepage https://github.com/eden-tech-labs/json-2-php-class
Informations about the package json-2-php-class
json-2-php-class
Creates object of native classes from JSON string or object json-2-php-class is a library for converting json objects to native classes.
Requirements
- PHP 7.2 and above. (Should be checked!)
Installation
1. Using Composer
You can install the library via Composer. If you don't already have Composer installed, first install it from here.
After composer is installed, Then run the following command to install the json-2-php-class library:
2. Manually
Warning: You have to require
the used classes or make an autoload function to do this.
If you're not using Composer, you can also clone eden-tech-labs/json-2-php-class
repository into a directory in your project:
However, using Composer is recommended as you can easily keep the library up-to-date and deal with autoloading.
Usage
After you installed json-2-php-class
library, in your classes you should implement the interface
and use
the trait and that satisfies the interface
requirements.
After that you should override the _mapping()
method. You can check the implementation and documentation below.
You can define your properties in the class or in the PHPDoc
as in the example. After you define your properties rules you can export PHPDoc
. Example below.(TODO: put link here)
Sample Class
Sample Usage
Output:
As a property mapping
you can define this types:
int
Integerstring
Stringfloat
Any Number that has fraction partbool
Booleanmilliseconds
PHP DateTime object generated from string or int containing timestamp in millisecondsseconds
PHP DateTime object generated from string or int containing timestamp in secondsjson
Standard PHP object generated troughjson_decode
unknown
The value is assigned to the property without any transformations.AnyClass::class
- If
implements MadeFromDataContract
an object will be created usingmake
function - Any other class will be created by
__construct
passing thevalue
as first and only parameter.
- If
Closure
To be defined.
PHPDoc
Example
Output