Neos\Flow\ResourceManagement\PersistentResource::setSha1 PHP Method

setSha1() public method

Sets the SHA1 hash of the content of this resource
public setSha1 ( string $sha1 ) : void
$sha1 string The sha1 hash
return void
    public function setSha1($sha1)
    {
        $this->throwExceptionIfProtected();
        if (preg_match('/[a-f0-9]{40}/', $sha1) !== 1) {
            throw new \InvalidArgumentException('Specified invalid hash to setSha1()', 1362564220);
        }
        $this->sha1 = $sha1;
    }

Usage Example

コード例 #1
0
 /**
  * Imports the given temporary file into the storage and creates the new resource object.
  *
  * Note: the temporary file is (re-)moved by this method.
  *
  * @param string $temporaryPathAndFileName
  * @param string $collectionName
  * @return PersistentResource
  * @throws StorageException
  */
 protected function importTemporaryFile($temporaryPathAndFileName, $collectionName)
 {
     $this->fixFilePermissions($temporaryPathAndFileName);
     $sha1Hash = sha1_file($temporaryPathAndFileName);
     $targetPathAndFilename = $this->getStoragePathAndFilenameByHash($sha1Hash);
     if (!is_file($targetPathAndFilename)) {
         $this->moveTemporaryFileToFinalDestination($temporaryPathAndFileName, $targetPathAndFilename);
     } else {
         unlink($temporaryPathAndFileName);
     }
     $resource = new PersistentResource();
     $resource->setFileSize(filesize($targetPathAndFilename));
     $resource->setCollectionName($collectionName);
     $resource->setSha1($sha1Hash);
     $resource->setMd5(md5_file($targetPathAndFilename));
     return $resource;
 }