Beispiel #1
0
 /**
  * @param string $namespace
  * @param FileUpload $fileUpload
  * @return SplFileInfo
  * @throws NotAllowedFileException
  */
 public function upload($namespace, FileUpload $fileUpload)
 {
     $filename = Utils::sanitizeFileName($fileUpload);
     $fileInfo = new SplFileInfo($filename);
     $suffix = $fileInfo->getExtension();
     if (in_array($suffix, $this->blacklist)) {
         throw new NotAllowedFileException("Upload of the file with {$suffix} suffix is not allowed.");
     }
     $destination = $this->storage->save($fileUpload->getTemporaryFile(), "{$namespace}/{$filename}");
     return new SplFileInfo($destination);
 }
Beispiel #2
0
 /**
  * @param $namespace
  * @param $filter
  * @return array
  */
 public function find($namespace, $filter)
 {
     $dir = Utils::normalizePath($this->basePath . '/' . $this->relativePath . '/' . $namespace);
     if (!is_dir($dir)) {
         return [];
     }
     $result = [];
     foreach (Finder::findFiles($filter)->in($dir) as $filePath => $file) {
         $result[$filePath] = $file;
     }
     return $result;
 }
Beispiel #3
0
 /**
  * @param string $namespace
  * @param FileUpload $fileUpload
  * @return SplFileInfo
  * @throws UploadErrorException
  */
 public function singleFileToDir($namespace, FileUpload $fileUpload)
 {
     if ($error = $fileUpload->getError()) {
         throw new UploadErrorException($error);
     }
     /** @var IManager $manager */
     $manager = $this->managerProvider->get($fileUpload);
     $relativePath = Utils::normalizePath($manager->getStorage()->getRelativePath() . '/' . $namespace);
     $this->onFileBegin($fileUpload, $relativePath);
     $uploadedFile = $manager->upload($namespace, $fileUpload);
     $this->onFileComplete($uploadedFile, $fileUpload, $relativePath);
     return $uploadedFile;
 }
Beispiel #4
0
 /**
  * @param string $dir
  * @param string $filename
  * @return void
  */
 public function delete($dir, $filename)
 {
     $filter = array_keys($this->dimensions);
     if ($this->saveOriginal) {
         $filter[] = 'orig';
     }
     $filter = array_map(function ($i) use($filename) {
         return $i . '_' . $filename;
     }, $filter);
     $filter[] = $filename;
     $dir = $this->getBasePath() . '/' . $this->getRelativePath() . '/' . $dir;
     $dir = Utils::normalizePath($dir);
     if (!is_dir($dir)) {
         return;
     }
     foreach (Finder::findFiles($filter)->in($dir) as $filePath => $file) {
         FileSystem::delete($filePath);
     }
 }
Beispiel #5
0
 /**
  * @param FileUpload $fileUpload
  * @param NULL|string $dir
  * @return SplFileInfo
  * @throws UploadErrorException
  */
 public function singleFileToDir(FileUpload $fileUpload, $dir = NULL)
 {
     if ($error = $fileUpload->getError()) {
         throw new UploadErrorException($error);
     }
     $name = $fileUpload->isImage() ? 'imageManager' : 'fileManager';
     /** @var IUploadManager $usedManager */
     $usedManager = $this->{$name};
     $path = Utils::normalizePath($usedManager->getRelativePath() . '/' . $dir);
     $this->onFileBegin($fileUpload, $path);
     $uploadedFile = $usedManager->upload($fileUpload, $dir);
     $this->onFileComplete($fileUpload, $uploadedFile, $path);
     return $uploadedFile;
 }
Beispiel #6
0
 /**
  * @param $namespace
  * @param $filter
  * @return array
  */
 public function find($namespace, $filter)
 {
     $pattern = self::buildPattern($filter);
     $iterator = $this->s3Client->getIterator('ListObjects', ['Bucket' => $this->basePath, 'Prefix' => Utils::normalizePath($this->relativePath . '/' . $namespace)]);
     $results = [];
     foreach ($iterator as $object) {
         if (!$pattern || preg_match($pattern, '/' . strtr($object['Key'], '\\', '/'))) {
             $url = $this->s3Client->getObjectUrl($this->basePath, $object['Key']);
             $results[$url] = new \SplFileInfo($url);
         }
     }
     return $results;
 }
Beispiel #7
0
 /**
  * @param $dir
  * @param $filename
  * @return mixed|void
  */
 public function delete($dir, $filename)
 {
     $dir = $this->getBasePath() . '/' . $this->getRelativePath() . '/' . $dir;
     $dir = Utils::normalizePath($dir);
     FileSystem::delete($dir . '/' . $filename);
 }
Beispiel #8
0
 /**
  * @param string $namespace
  * @param string $filename
  * @return void
  */
 public function delete($namespace, $filename)
 {
     $filter = array_keys($this->dimensions);
     if ($this->saveOriginal) {
         $filter[] = 'orig';
     }
     $filter = array_map(function ($i) use($filename) {
         return $i . '_' . $filename;
     }, $filter);
     $filter[] = $filename;
     $files = [];
     /** @var SplFileInfo $file */
     foreach ($this->storage->find($namespace, $filter) as $file) {
         $files[] = Utils::normalizePath($namespace . '/' . $file->getFilename());
     }
     $this->storage->bulkDelete($files);
 }