private function doSerializeResource(Resource $resource, $depth = 0) { $data = array(); $repositoryAlias = $this->registry->getRepositoryAlias($resource->getRepository()); $data['repository_alias'] = $repositoryAlias; $data['repository_type'] = $this->registry->getRepositoryType($resource->getRepository()); $data['payload_alias'] = $this->payloadAliasRegistry->getPayloadAlias($resource); $data['payload_type'] = null; if ($resource instanceof CmfResource) { $data['payload_type'] = $resource->getPayloadType(); } $data['path'] = $resource->getPath(); $data['label'] = $data['node_name'] = PathHelper::getNodeName($data['path']); $data['repository_path'] = $resource->getRepositoryPath(); $enhancers = $this->enhancerRegistry->getEnhancers($repositoryAlias); $children = array(); foreach ($resource->listChildren() as $name => $childResource) { $children[$name] = array(); if ($depth < 2) { $children[$name] = $this->doSerializeResource($childResource, $depth + 1); } } $data['children'] = $children; if ($resource instanceof BodyResource) { $data['body'] = $resource->getBody(); } foreach ($enhancers as $enhancer) { $data = $enhancer->enhance($data, $resource); } return $data; }
/** * Return the alias for the given PHPCR resource. * * @param resource $resource * * @return string */ public function getPayloadAlias(Resource $resource) { $repositoryType = $this->repositoryRegistry->getRepositoryType($resource->getRepository()); $type = null; if ($resource instanceof CmfResource) { $type = $resource->getPayloadType(); } if (null === $type) { return; } if (!isset($this->aliasesByRepository[$repositoryType])) { return; } if (!isset($this->aliasesByRepository[$repositoryType][$type])) { return; } return $this->aliasesByRepository[$repositoryType][$type]; }