https://github.com/lstrojny/objectconpherter
Object converter for PHP 5.3
https://github.com/lstrojny/objectconpherter
Last synced: about 1 month ago
JSON representation
Object converter for PHP 5.3
- Host: GitHub
- URL: https://github.com/lstrojny/objectconpherter
- Owner: lstrojny
- Created: 2011-01-21T21:49:31.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-12-05T00:17:55.000Z (over 13 years ago)
- Last Synced: 2025-02-25T17:43:54.949Z (4 months ago)
- Language: PHP
- Homepage:
- Size: 933 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
ObjectConpherter
================
[](http://travis-ci.org/lstrojny/ObjectConpherter)
Converting PHP Objects Into Array Representations Since 2011Mission Statement
-----------------ObjectConpherter takes your business objects and converts them into arrays while
keeping there hierarchial structure. The project was born because [we](http://jarlssen.de)
needed a system to provide array representations of business objects for a JSON API.License
-------Licensed under New BSD License
Current Use Cases
------------------ Property mapping support for the concrete class, superclass(es), interfaces
- Filter infrastructure to allow implementing conversions for specific types
(e.g. formatting date specifically), renaming of properties (if you use an
underscore with protected properties, you might not want to show that in
your API)
- Configuration readers to support defining export properties as Annotations
and in XML. For the sake of speed there might be a configuration dumper
component to convert annotations into plain PHP
- A minimal, XQuery-alike interface to define conversion depth of objects.
"/root/_foo/_bar" will export the property "_foo" of the object passed and
the property "_bar" of "_foo"Usage
-----```php
name = $name;
}
}$user = new User('John Doe');
$user->id = 23;
$user->friends[] = new User('Max Mustermann');$configuration = new ObjectConpherter\Configuration\Configuration();
$configuration->exportProperties('User', array('id', 'name', 'friends'));
$converter = new ObjectConpherter\Converter\Converter($configuration);
var_dump($converter->convert($user, null, '/root/*', '/root/friends/*/name'));
```Will output:
array(3) {
["id"]=>
int(23)
["name"]=>
string(8) "John Doe"
["friends"]=>
array(1) {
[0]=>
array(1) {
["name"]=>
string(14) "Max Mustermann"
}
}
}Thank you!
----------This software is based on good ideas of Marc Jakubowski ,
Max Beutel , Karsten Gohm , Stefan Matheis