/** * Gets a relative filesystem path based on the repository path, AND * creates the file on the filesystem if it's in the repository * and not yet on the filesystem. * The repository path points to a nt-resource node, whose title * should be the filename, and which has a child+property * jcr:content/jcr:data where the file data is stored. * * @param string $path path to the nt-resource node. * @return string with a path to the file, relative to the web directory. */ public function getUrl(NodeInterface $node) { $hasData = false; if ($node->hasNode('jcr:content')) { $contentNode = $node->getNode('jcr:content'); if ($contentNode->hasProperty('jcr:data')) { $hasData = true; } } if (!$hasData) { //TODO: notfound exception is not appropriate ... how to best do this? //throw new NotFoundHttpException('no picture found at ' . $node->getPath()); return 'notfound'; } $path = $node->getPath(); $relativePath = $this->pathMapper->getUrl($path); $extension = $this->getExtension($contentNode); $fullPath = $this->fileBasePath . '/' . $relativePath . $extension; if (!file_exists($fullPath)) { if (!$this->saveData($contentNode, $fullPath)) { throw new FileException('failed to save data to file: ' . $fullPath); } } return $this->webRelativePath . '/' . $relativePath . $extension; }
/** * Gets a relative filesystem path based on the repository path, AND * creates the file on the filesystem if it's in the repository * and not yet on the filesystem. * The repository path points to a nt-resource node, whose title * should be the filename, and which has a child+property * jcr:content/jcr:data where the file data is stored. * * @param string $path path to the nt-resource node. * @return string with a path to the file, relative to the web directory. */ public function getUrl(NodeInterface $node) { $hasData = false; if ($node->hasNode('jcr:content')) { $contentNode = $node->getNode('jcr:content'); if ($contentNode->hasProperty('jcr:data')) { $hasData = true; } } if (!$hasData) { //TODO: notfound exception is not appropriate ... how to best do this? //throw new NotFoundHttpException('no picture found at ' . $node->getPath()); return 'notfound'; } $path = $node->getPath(); $relativePath = $this->pathMapper->getUrl($path); $fullPath = $this->fileBasePath . $relativePath . $this->getExtension($contentNode); if (!file_exists($fullPath)) { try { $this->saveData($contentNode, $fullPath); } catch (Imagine\Exception\Exception $e) { //TODO: notfound exception is not appropriate ... how to best do this? //throw new NotFoundHttpException('image save to filesystem failed: ' . $e->getMessage()); return 'notfound'; } } return $this->webRelativePath . $relativePath . $this->getExtension($contentNode); }