getPublicPersistentResourceUri() public method

Returns the web accessible URI for the given resource object
public getPublicPersistentResourceUri ( PersistentResource $resource ) : string | boolean
$resource PersistentResource The resource object
return string | boolean A URI as a string or FALSE if the collection of the resource is not found
 /**
  * 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 PersistentResource $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, PersistentResource $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;
 }
 /**
  * Upload a new image and return an image variant, a thumbnail and additional information like it would be
  * returned for the Neos backend.
  *
  * @param Image $image
  * @return string
  */
 public function uploadAction(Image $image)
 {
     $this->assetRepository->add($image);
     $imageVariant = new ImageVariant($image);
     $this->assetRepository->add($imageVariant);
     $thumbnail = $image->getThumbnail(100, 100);
     $this->response->setHeader('Content-Type', 'application/json');
     return json_encode(array('__identity' => $this->persistenceManager->getIdentifierByObject($image), '__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($image->getResource()), 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'thumbnail' => array('__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($thumbnail->getResource()), 'width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()), 'variants' => array(array('__identity' => $this->persistenceManager->getIdentifierByObject($imageVariant), '__resourceUri' => $this->resourceManager->getPublicPersistentResourceUri($imageVariant->getResource()), 'width' => $imageVariant->getWidth(), 'height' => $imageVariant->getHeight()))));
 }
 /**
  * Resolves a given asset:// URI to a "normal" HTTP(S) URI for the addressed asset's resource.
  *
  * @param string|Uri $uri
  * @return string
  */
 public function resolveAssetUri($uri)
 {
     $targetObject = $this->convertUriToObject($uri);
     if ($targetObject === null) {
         $this->systemLogger->log(sprintf('Could not resolve "%s" to an existing asset; The asset was probably deleted.', $uri));
         return null;
     }
     return $this->resourceManager->getPublicPersistentResourceUri($targetObject->getResource());
 }
 /**
  * @param Image $image
  * @return array
  */
 protected function getImagePreviewData(Image $image)
 {
     $imageProperties = ['originalImageResourceUri' => $this->resourceManager->getPublicPersistentResourceUri($image->getResource()), 'originalDimensions' => ['width' => $image->getWidth(), 'height' => $image->getHeight(), 'aspectRatio' => $image->getAspectRatio()], 'mediaType' => $image->getResource()->getMediaType()];
     $thumbnail = $this->thumbnailService->getThumbnail($image, $this->thumbnailService->getThumbnailConfigurationForPreset('Neos.Media.Browser:Preview'));
     if ($thumbnail !== null) {
         $imageProperties['previewImageResourceUri'] = $this->thumbnailService->getUriForThumbnail($thumbnail);
         $imageProperties['previewDimensions'] = ['width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()];
     }
     return $imageProperties;
 }
 /**
  * @param ImageInterface $thumbnail
  * @return string
  * @throws ThumbnailServiceException
  */
 public function getUriForThumbnail(ImageInterface $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);
     }
     return $this->resourceManager->getPublicPackageResourceUriByPath($staticResource);
 }
 /**
  * Returns the absolute URL of a resource
  *
  * @return string
  * @throws TypoScriptException
  */
 public function evaluate()
 {
     $resource = $this->getResource();
     if ($resource !== null) {
         $uri = false;
         if ($resource instanceof PersistentResource) {
             $uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
         }
         if ($uri === false) {
             throw new TypoScriptException('The specified resource is invalid', 1386458728);
         }
         return $uri;
     }
     $path = $this->getPath();
     if ($path === null) {
         throw new TypoScriptException('Neither "resource" nor "path" were specified', 1386458763);
     }
     if (strpos($path, 'resource://') === 0) {
         $matches = array();
         if (preg_match('#^resource://([^/]+)/Public/(.*)#', $path, $matches) !== 1) {
             throw new TypoScriptException(sprintf('The specified path "%s" does not point to a public resource.', $path), 1386458851);
         }
         $package = $matches[1];
         $path = $matches[2];
     } else {
         $package = $this->getPackage();
         if ($package === null) {
             $controllerContext = $this->tsRuntime->getControllerContext();
             /** @var $actionRequest ActionRequest */
             $actionRequest = $controllerContext->getRequest();
             $package = $actionRequest->getControllerPackageKey();
         }
     }
     $localize = $this->isLocalize();
     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];
         }
     }
     return $this->resourceManager->getPublicPackageResourceUri($package, $path);
 }
 /**
  * Replace resource on an asset. Takes variants and redirect handling into account.
  *
  * @param AssetInterface $asset
  * @param PersistentResource $resource
  * @param array $options
  * @return void
  */
 public function replaceAssetResource(AssetInterface $asset, PersistentResource $resource, array $options = [])
 {
     $originalAssetResource = $asset->getResource();
     $asset->setResource($resource);
     if (isset($options['keepOriginalFilename']) && (bool) $options['keepOriginalFilename'] === true) {
         $asset->getResource()->setFilename($originalAssetResource->getFilename());
     }
     $uriMapping = [];
     $redirectHandlerEnabled = isset($options['generateRedirects']) && (bool) $options['generateRedirects'] === true && $this->packageManager->isPackageAvailable('Neos.RedirectHandler');
     if ($redirectHandlerEnabled) {
         $uriMapping[$this->resourceManager->getPublicPersistentResourceUri($originalAssetResource)] = $this->resourceManager->getPublicPersistentResourceUri($asset->getResource());
     }
     if (method_exists($asset, 'getVariants')) {
         $variants = $asset->getVariants();
         /** @var AssetVariantInterface $variant */
         foreach ($variants as $variant) {
             $originalVariantResource = $variant->getResource();
             $variant->refresh();
             if (method_exists($variant, 'getAdjustments')) {
                 foreach ($variant->getAdjustments() as $adjustment) {
                     if (method_exists($adjustment, 'refit')) {
                         $adjustment->refit($asset);
                     }
                 }
             }
             if ($redirectHandlerEnabled) {
                 $uriMapping[$this->resourceManager->getPublicPersistentResourceUri($originalVariantResource)] = $this->resourceManager->getPublicPersistentResourceUri($variant->getResource());
             }
             $this->getRepository($variant)->update($variant);
         }
     }
     if ($redirectHandlerEnabled) {
         /** @var \Neos\RedirectHandler\Storage\RedirectStorageInterface $redirectStorage */
         $redirectStorage = $this->objectManager->get(\Neos\RedirectHandler\Storage\RedirectStorageInterface::class);
         foreach ($uriMapping as $originalUri => $newUri) {
             $existingRedirect = $redirectStorage->getOneBySourceUriPathAndHost($originalUri);
             if ($existingRedirect === null) {
                 $redirectStorage->addRedirect($originalUri, $newUri, 301);
             }
         }
     }
     $this->getRepository($asset)->update($asset);
     $this->emitAssetResourceReplaced($asset);
 }
 /**
  * Returns the URI pointing to the published persistent resource
  *
  * @param PersistentResource $resource The resource to publish
  * @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
  * @deprecated since Flow 3.0. Use ResourceManager->getPublicPersistentResourceUri($resource) instead
  */
 public function getPersistentResourceWebUri(PersistentResource $resource)
 {
     $this->systemLogger->log('The deprecated method ResourcePublisher->getPersistentResourceWebUri() has been called' . $this->getCallee() . '. Please use ResourceManager->getPublicPersistentResourceUri() instead!', LOG_WARNING);
     return $this->resourceManager->getPublicPersistentResourceUri($resource);
 }