Neos\Flow\ResourceManagement\ResourceManager::getStreamByResource PHP Метод

getStreamByResource() публичный Метод

Returns a stream handle of the given persistent resource which allows for opening / copying the resource's data. Note that this stream handle may only be used read-only.
public getStreamByResource ( PersistentResource $resource ) : resource | boolean
$resource PersistentResource The resource to retrieve the stream for
Результат resource | boolean The resource stream or FALSE if the stream could not be obtained
    public function getStreamByResource(PersistentResource $resource)
    {
        $this->initialize();
        $collectionName = $resource->getCollectionName();
        if (!isset($this->collections[$collectionName])) {
            return false;
        }
        return $this->collections[$collectionName]->getStreamByResource($resource);
    }

Usage Example

 /**
  * Evaluates the absolute path and filename of the resource file specified
  * by the given path.
  *
  * @param string $requestedPath
  * @param boolean $checkForExistence Whether a (non-hash) path should be checked for existence before being returned
  * @return mixed The full path and filename or FALSE if the file doesn't exist
  * @throws \InvalidArgumentException|ResourceException
  */
 protected function evaluateResourcePath($requestedPath, $checkForExistence = true)
 {
     if (substr($requestedPath, 0, strlen(self::SCHEME)) !== self::SCHEME) {
         throw new \InvalidArgumentException('The ' . __CLASS__ . ' only supports the \'' . self::SCHEME . '\' scheme.', 1256052544);
     }
     $uriParts = Functions::parse_url($requestedPath);
     if (!is_array($uriParts) || !isset($uriParts['host'])) {
         return false;
     }
     if (preg_match('/^[0-9a-f]{40}$/i', $uriParts['host']) === 1) {
         $resource = $this->resourceManager->getResourceBySha1($uriParts['host']);
         return $this->resourceManager->getStreamByResource($resource);
     }
     if (!$this->packageManager->isPackageAvailable($uriParts['host'])) {
         throw new ResourceException(sprintf('Invalid resource URI "%s": Package "%s" is not available.', $requestedPath, $uriParts['host']), 1309269952);
     }
     $package = $this->packageManager->getPackage($uriParts['host']);
     $resourceUri = Files::concatenatePaths([$package->getResourcesPath(), $uriParts['path']]);
     if ($checkForExistence === false || file_exists($resourceUri)) {
         return $resourceUri;
     }
     return false;
 }
All Usage Examples Of Neos\Flow\ResourceManagement\ResourceManager::getStreamByResource