Neos\Flow\ResourceManagement\ResourceRepository::findOneBySha1 PHP Метод

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

Find one resource by SHA1
public findOneBySha1 ( string $sha1Hash ) : PersistentResource
$sha1Hash string
Результат PersistentResource
    public function findOneBySha1($sha1Hash)
    {
        $query = $this->createQuery();
        $query->matching($query->equals('sha1', $sha1Hash))->setLimit(1);
        /** @var PersistentResource $resource */
        $resource = $query->execute()->getFirst();
        if ($resource === null) {
            /** @var PersistentResource $importedResource */
            foreach ($this->addedResources as $importedResource) {
                if ($importedResource->getSha1() === $sha1Hash) {
                    return $importedResource;
                }
            }
        }
        return $resource;
    }

Usage Example

 /**
  * Returns the web accessible URI for the resource object specified by the
  * given SHA1 hash.
  *
  * @param string $resourceHash The SHA1 hash identifying the resource content
  * @param string $collectionName Name of the collection the resource is part of
  * @return string A URI as a string
  * @throws Exception
  * @api
  */
 public function getPublicPersistentResourceUriByHash($resourceHash, $collectionName = self::DEFAULT_PERSISTENT_COLLECTION_NAME)
 {
     $this->initialize();
     if (!isset($this->collections[$collectionName])) {
         throw new Exception(sprintf('Could not determine persistent resource URI for "%s" because the specified collection "%s" does not exist.', $resourceHash, $collectionName), 1375197875);
     }
     /** @var TargetInterface $target */
     $target = $this->collections[$collectionName]->getTarget();
     $resource = $this->resourceRepository->findOneBySha1($resourceHash);
     if ($resource === null) {
         throw new Exception(sprintf('Could not determine persistent resource URI for "%s" because no PersistentResource object with that SHA1 hash could be found.', $resourceHash), 1375347691);
     }
     return $target->getPublicPersistentResourceUri($resource);
 }
All Usage Examples Of Neos\Flow\ResourceManagement\ResourceRepository::findOneBySha1