/** * Render the URI to the resource. The filename is used from child content. * * @param string $path The location of the resource, can be either a path relative to the Public resource directory of the package or a resource://... URI * @param string $package Target package key. If not set, the current package key will be used * @param Resource $resource If specified, this resource object is used instead of the path and package information * @param boolean $localize Whether resource localization should be attempted or not * @return string The absolute URI to the resource * @throws InvalidVariableException * @api */ public function render($path = null, $package = null, Resource $resource = null, $localize = true) { if ($resource !== null) { $uri = $this->resourceManager->getPublicPersistentResourceUri($resource); if ($uri === false) { $uri = '404-Resource-Not-Found'; } } else { if ($path === null) { throw new InvalidVariableException('The ResourceViewHelper did neither contain a valuable "resource" nor "path" argument.', 1353512742); } if ($package === null) { $package = $this->controllerContext->getRequest()->getControllerPackageKey(); } if (strpos($path, 'resource://') === 0) { try { list($package, $path) = $this->resourceManager->getPackageAndPathByPublicPath($path); } catch (Exception $exception) { throw new InvalidVariableException(sprintf('The specified path "%s" does not point to a public resource.', $path), 1386458851); } } if ($localize === true) { $resourcePath = 'resource://' . $package . '/Public/' . $path; $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath); $matches = array(); if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) { $package = $matches[1]; $path = $matches[2]; } } $uri = $this->resourceManager->getPublicPackageResourceUri($package, $path); } return $uri; }
/** * @param Thumbnail $thumbnail * @return string * @throws ThumbnailServiceException */ public function getUriForThumbnail(Thumbnail $thumbnail) { $resource = $thumbnail->getResource(); if ($resource) { return $this->resourceManager->getPublicPersistentResourceUri($resource); } $staticResource = $thumbnail->getStaticResource(); if ($staticResource === null) { throw new ThumbnailServiceException(sprintf('Could not generate URI for static thumbnail "%s".', $this->persistenceManager->getIdentifierByObject($thumbnail)), 1450178437); } try { list($package, $path) = $this->resourceManager->getPackageAndPathByPublicPath($staticResource); return $this->resourceManager->getPublicPackageResourceUri($package, $path); } catch (Exception $exception) { return $staticResource; } }