Esempio n. 1
0
 public function deleteFile($file, StorageConfig $config)
 {
     $filePath = rtrim($config->resolvePath($this->owner), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
     if (!empty($config->filesystem)) {
         if ($config->filesystem->has($filePath)) {
             $config->filesystem->delete($filePath);
         }
     } else {
         @unlink($filePath);
     }
 }
Esempio n. 2
0
 /**
  * @param UploadedFile $uploadedFile
  * @param StorageConfig $config
  * @return FileInterface|null
  */
 protected function saveUploadedFile(UploadedFile $uploadedFile, StorageConfig $config)
 {
     $relation = $this->owner->getRelation($config->relation);
     /** @var FileInterface $fileClass */
     $fileClass = $relation->modelClass;
     $file = $fileClass::getInstanceFromUploadedFile($uploadedFile);
     $filesystemComponent = $this->getFilesystemComponent();
     $path = $config->resolveFilePath($uploadedFile->name, $this->owner);
     if (isset($config->events['beforeSave']) && $config->events['beforeSave'] instanceof \Closure) {
         call_user_func($config->events['beforeSave'], $file, $path, $config->filesystem);
     }
     if ($path = $filesystemComponent->saveFile($file, $config->filesystem, $path, false, true)) {
         $file->setPath($path);
         $file->setFilesystemName($config->filesystem);
         return $file;
     } else {
         return null;
     }
 }