Add jsonSerialize method to RelationalEntity

Signed-off-by: Julius Haertl <jus@bitgrid.net>
This commit is contained in:
Julius Haertl
2017-03-05 13:43:54 +01:00
committed by Julius Härtl
parent 3324556542
commit 34c1a681b1
8 changed files with 45 additions and 70 deletions

View File

@@ -21,17 +21,10 @@
*
*/
/**
* Created by PhpStorm.
* User: jus
* Date: 22.06.16
* Time: 13:32
*/
namespace OCA\Deck\Db;
class RelationalEntity extends \OCP\AppFramework\Db\Entity {
class RelationalEntity extends \OCP\AppFramework\Db\Entity implements \JsonSerializable {
private $_relations = array();
@@ -56,4 +49,21 @@ class RelationalEntity extends \OCP\AppFramework\Db\Entity {
}
}
/**
* @return array serialized data
*/
public function jsonSerialize() {
$properties = get_object_vars($this);
$reflection = new \ReflectionClass($this);
$json = [];
foreach($properties as $property=>$value) {
if(substr($property, 0, 1) !== '_' && $reflection->hasProperty($property)) {
$propertyReflection = $reflection->getProperty($property);
if(!$propertyReflection->isPrivate()) {
$json[$property] = $this->getter($property);
}
}
}
return $json;
}
}