/** * Publishes a persistent resource to the web accessible resources directory. * * @param \F3\FLOW3\Resource\Resource $resource The resource to publish * @param string $title An optional title which is used in the public URI pointing to the published resource * @return mixed Either the web URI of the published resource or FALSE if the resource source file doesn't exist or the resource could not be published for other reasons * @author Robert Lemke <*****@*****.**> */ public function publishPersistentResource(\F3\FLOW3\Resource\Resource $resource, $title = '') { $rewrittenTitle = $title === '' ? '' : '/' . $this->rewriteTitleForUri($title); $publishedResourcePathAndFilename = $this->resourcesPublishingPath . 'Persistent/' . $resource->getHash() . '.' . $resource->getFileExtension(); $publishedResourceWebUri = $this->resourcesBaseUri . 'Persistent/' . $resource->getHash() . $rewrittenTitle . '.' . $resource->getFileExtension(); if (!file_exists($publishedResourcePathAndFilename)) { $unpublishedResourcePathAndFilename = $this->getPersistentResourceSourcePathAndFilename($resource); if ($unpublishedResourcePathAndFilename === FALSE) { return FALSE; } $this->mirrorFile($unpublishedResourcePathAndFilename, $publishedResourcePathAndFilename, FALSE); } return $publishedResourceWebUri; }
/** * Returns the private path to the source of the given resource. * * @param \F3\FLOW3\Resource\Resource $resource * @return mixed The full path and filename to the source of the given resource or FALSE if the resource file doesn't exist * @author Robert Lemke <*****@*****.**> */ protected function getPersistentResourceSourcePathAndFilename(\F3\FLOW3\Resource\Resource $resource) { $pathAndFilename = FLOW3_PATH_DATA . 'Persistent/Resources/' . $resource->getHash(); return file_exists($pathAndFilename) ? $pathAndFilename : FALSE; }
/** * Deletes the file represented by the given resource instance. * * @param \F3\FLOW3\Resource\Resource $resource * @return boolean * @author Karsten Dambekalns <*****@*****.**> */ public function deleteResource($resource) { if ($resource instanceof \F3\FLOW3\Resource\Resource) { if (is_file($this->persistentResourcesStorageBaseUri . $resource->getHash())) { unlink($this->persistentResourcesStorageBaseUri . $resource->getHash()); } } }