/** * Converts entity to DOMElement * * @param Model\Entity $entity * @return DOMElement */ protected function convertEntity(Model\Entity $entity) { $xmlEntity = $this->xmlDoc->createElement('entity'); $xmlEntity->appendChild($this->xmlDoc->createElement('uuid', $entity->getUuid())); $xmlEntity->appendChild($this->xmlDoc->createElement('type', $entity->getType())); foreach ($entity->getProperties() as $key => $value) { $xmlEntity->appendChild($this->xmlDoc->createElement($key, $value)); } return $xmlEntity; }
/** * Converts entity to array for json_encode() * * @param Model\Entity $entity * @return array */ protected static function convertEntity(Model\Entity $entity, $chain = array()) { $jsonEntity = array(); $jsonEntity['uuid'] = (string) $entity->getUuid(); $jsonEntity['type'] = $entity->getType(); foreach ($entity->getProperties() as $key => $value) { $jsonEntity[$key] = $value; } if ($entity instanceof Model\Aggregator) { $chain[$entity->getUuid()] = 1; foreach ($entity->getChildren() as $child) { if (array_key_exists($child->getUuid(), $chain)) { continue; } # don't ever loop back $jsonEntity['children'][] = self::convertEntity($child, $chain); } } return $jsonEntity; }
/** * Converts entity to array for json_encode() * * @param Model\Entity $entity * @return array */ protected static function convertEntity(Model\Entity $entity) { $jsonEntity = array(); $jsonEntity['uuid'] = (string) $entity->getUuid(); $jsonEntity['type'] = $entity->getType(); foreach ($entity->getProperties() as $key => $value) { $jsonEntity[$key] = $value; } if ($entity instanceof Model\Aggregator) { foreach ($entity->getChildren() as $child) { $jsonEntity['children'][] = self::convertEntity($child); } } return $jsonEntity; }