Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abgeo/json-to-popo
Fill Plain Old PHP Object with JSON content.
https://github.com/abgeo/json-to-popo
composer data-types json json-parser php php-library plain-old-php-object popo
Last synced: about 6 hours ago
JSON representation
Fill Plain Old PHP Object with JSON content.
- Host: GitHub
- URL: https://github.com/abgeo/json-to-popo
- Owner: ABGEO
- License: mit
- Created: 2020-04-29T18:23:10.000Z (over 4 years ago)
- Default Branch: 1.x
- Last Pushed: 2021-04-29T21:41:00.000Z (over 3 years ago)
- Last Synced: 2024-10-25T19:56:10.021Z (11 days ago)
- Topics: composer, data-types, json, json-parser, php, php-library, plain-old-php-object, popo
- Language: PHP
- Size: 72.3 KB
- Stars: 12
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# json-to-popo
Fill Plain Old PHP Object with JSON content.
[![Build Status](https://travis-ci.com/ABGEO/json-to-popo.svg?branch=1.x)](https://travis-ci.com/ABGEO/json-to-popo?branch=1.x)
[![Coverage Status](https://coveralls.io/repos/github/ABGEO/json-to-popo/badge.svg?branch=1.x)](https://coveralls.io/github/ABGEO/json-to-popo?branch=1.x)
[![GitHub release](https://img.shields.io/github/release/ABGEO/json-to-popo.svg)](https://github.com/ABGEO/json-to-popo/releases)
[![Packagist Version](https://img.shields.io/packagist/v/abgeo/json-to-popo.svg)](https://packagist.org/packages/abgeo/json-to-popo)
[![GitHub license](https://img.shields.io/github/license/ABGEO/json-to-popo.svg)](https://github.com/ABGEO/json-to-popo/blob/master/LICENSE)## Installation
You can install this library with [Composer](https://getcomposer.org/):
- `composer require abgeo/json-to-popo`
## Usage
Include composer autoloader in your main file (Ex.: index.php)
- `require __DIR__.'/../vendor/autoload.php';`
Consider that you have `example.json` with the following content:
```json
{
"firstName": "Temuri",
"lastName": "Takalandze",
"active": true,
"position": {
"title": "Developer",
"department": {
"title": "IT"
}
}
}
```and several POPO classes to represent this JSON data:
`Department.php`
```php
composeObject($jsonContent, Person::class);
```Print `$resultObject`:
```php
var_dump($resultObject);//class ABGEO\POPO\Example\Person#2 (4) {
// private $firstName =>
// string(6) "Temuri"
// private $lastName =>
// string(10) "Takalandze"
// private $active =>
// bool(true)
// private $position =>
// class ABGEO\POPO\Example\Position#4 (2) {
// private $title =>
// string(9) "Developer"
// private $department =>
// class ABGEO\POPO\Example\Department#7 (1) {
// private $title =>
// string(2) "IT"
// }
// }
//}
```**See full example [here](examples).**
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for details.
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
## Authors
- [**Temuri Takalandze**](https://abgeo.dev) - *Initial work*
## License
Copyright © 2020 [Temuri Takalandze](https://abgeo.dev).
Released under the [MIT](LICENSE) license.