/**
  * Return all Objects stored in this storage filtered by the given directory / filename pattern
  *
  * @param string $pattern A glob compatible directory / filename pattern
  * @return array<\TYPO3\Flow\Resource\Storage\Object>
  */
 public function getObjectsByPathPattern($pattern)
 {
     $objects = array();
     $directories = array();
     if (strpos($pattern, '/') !== false) {
         list($packageKeyPattern, $directoryPattern) = explode('/', $pattern, 2);
     } else {
         $packageKeyPattern = $pattern;
         $directoryPattern = '*';
     }
     // $packageKeyPattern can be used in a future implementation to filter by package key
     $packages = $this->packageManager->getActivePackages();
     foreach ($packages as $packageKey => $package) {
         /** @var PackageInterface $package */
         if ($directoryPattern === '*') {
             $directories[$packageKey][] = $package->getPackagePath();
         } else {
             $directories[$packageKey] = glob($package->getPackagePath() . $directoryPattern, GLOB_ONLYDIR);
         }
     }
     foreach ($directories as $packageKey => $packageDirectories) {
         foreach ($packageDirectories as $directoryPath) {
             foreach (Files::getRecursiveDirectoryGenerator($directoryPath) as $resourcePathAndFilename) {
                 $pathInfo = UnicodeFunctions::pathinfo($resourcePathAndFilename);
                 $object = new Object();
                 $object->setFilename($pathInfo['basename']);
                 $object->setSha1(sha1_file($resourcePathAndFilename));
                 $object->setMd5(md5_file($resourcePathAndFilename));
                 $object->setFileSize(filesize($resourcePathAndFilename));
                 if (isset($pathInfo['dirname'])) {
                     list(, $path) = explode('/', str_replace($packages[$packageKey]->getResourcesPath(), '', $pathInfo['dirname']), 2);
                     $object->setRelativePublicationPath($packageKey . '/' . $path . '/');
                 }
                 $object->setStream(function () use($resourcePathAndFilename) {
                     return fopen($resourcePathAndFilename, 'r');
                 });
                 $objects[] = $object;
             }
         }
     }
     return $objects;
 }
 /**
  * Retrieve all Objects stored in this storage, filtered by the given collection name
  *
  * @param callable $callback Function called after each iteration
  * @param CollectionInterface $collection
  * @return \Generator<Object>
  */
 public function getObjectsByCollection(CollectionInterface $collection, callable $callback = null)
 {
     $iterator = $this->resourceRepository->findByCollectionNameIterator($collection->getName());
     $iteration = 0;
     foreach ($this->resourceRepository->iterate($iterator, $callback) as $resource) {
         /** @var PersistentResource $resource */
         $object = new Object();
         $object->setFilename($resource->getFilename());
         $object->setSha1($resource->getSha1());
         $object->setMd5($resource->getMd5());
         $object->setFileSize($resource->getFileSize());
         $object->setStream(function () use($resource) {
             return $this->getStreamByResource($resource);
         });
         (yield $object);
         if (is_callable($callback)) {
             call_user_func($callback, $iteration, $object);
         }
         $iteration++;
     }
 }
 /**
  * Retrieve all Objects stored in this storage, filtered by the given collection name
  *
  * @param CollectionInterface $collection
  * @return array<\TYPO3\Flow\Resource\Storage\Object>
  */
 public function getObjectsByCollection(CollectionInterface $collection)
 {
     $objects = array();
     $that = $this;
     foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) {
         /** @var \TYPO3\Flow\Resource\Resource $resource */
         $object = new Object();
         $object->setFilename($resource->getFilename());
         $object->setSha1($resource->getSha1());
         $object->setMd5($resource->getMd5());
         $object->setFileSize($resource->getFileSize());
         $object->setStream(function () use($that, $resource) {
             return $that->getStreamByResource($resource);
         });
         $objects[] = $object;
     }
     return $objects;
 }
예제 #4
0
 /**
  * Retrieve all Objects stored in this storage, filtered by the given collection name
  *
  * @param CollectionInterface $collection
  * @internal param string $collectionName
  * @return array<\TYPO3\Flow\Resource\Storage\Object>
  * @api
  */
 public function getObjectsByCollection(CollectionInterface $collection)
 {
     $objects = array();
     $that = $this;
     $bucketName = $this->bucketName;
     foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) {
         /** @var \TYPO3\Flow\Resource\Resource $resource */
         $object = new Object();
         $object->setFilename($resource->getFilename());
         $object->setSha1($resource->getSha1());
         $object->setStream(function () use($that, $bucketName, $resource) {
             return fopen('s3://' . $bucketName . '/' . $this->keyPrefix . $resource->getSha1(), 'r');
         });
         $objects[] = $object;
     }
     return $objects;
 }
 /**
  * Retrieve all Objects stored in this storage, filtered by the given collection name
  *
  * @param CollectionInterface $collection
  * @internal param string $collectionName
  * @return array<\TYPO3\Flow\Resource\Storage\Object>
  * @api
  */
 public function getObjectsByCollection(CollectionInterface $collection)
 {
     if ($this->debug) {
         $this->systemLogger->log('storage ' . $this->name . ': getObjectsByCollection, $collection->getName(): ' . $collection->getName());
     }
     $objects = array();
     $that = $this;
     $containerName = $this->containerName;
     foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) {
         /** @var \TYPO3\Flow\Resource\Resource $resource */
         if ($this->debug) {
             $this->systemLogger->log('storage ' . $this->name . ': - getObjectsByCollection $resource->getFilename(): ' . $resource->getFilename());
         }
         $object = new Object();
         $object->setFilename($resource->getFilename());
         $object->setSha1($resource->getSha1());
         $object->setStream(function () use($that, $containerName, $resource) {
             return 'http://' . $this->zoneDomain . '/_' . $resource->getSha1();
         });
         $objects[] = $object;
     }
     return $objects;
 }