vendor/vich/uploader-bundle/src/Storage/FileSystemStorage.php line 41

Open in your IDE?
  1. <?php
  2. namespace Vich\UploaderBundle\Storage;
  3. use Symfony\Component\HttpFoundation\File\File;
  4. use Symfony\Component\HttpFoundation\File\UploadedFile;
  5. use Vich\UploaderBundle\Mapping\PropertyMapping;
  6. /**
  7.  * FileSystemStorage.
  8.  *
  9.  * @author Dustin Dobervich <ddobervich@gmail.com>
  10.  */
  11. class FileSystemStorage extends AbstractStorage
  12. {
  13.     protected function doUpload(PropertyMapping $mappingUploadedFile $file, ?string $dirstring $name): ?File
  14.     {
  15.         $uploadDir $mapping->getUploadDestination().\DIRECTORY_SEPARATOR.$dir;
  16.         return $file->move($uploadDir$name);
  17.     }
  18.     protected function doRemove(PropertyMapping $mapping, ?string $dirstring $name): ?bool
  19.     {
  20.         $file $this->doResolvePath($mapping$dir$name);
  21.         return \file_exists($file) && \unlink($file);
  22.     }
  23.     protected function doResolvePath(PropertyMapping $mapping, ?string $dirstring $name, ?bool $relative false): string
  24.     {
  25.         $path = !empty($dir) ? $dir.\DIRECTORY_SEPARATOR.$name $name;
  26.         if ($relative) {
  27.             return $path;
  28.         }
  29.         return $mapping->getUploadDestination().\DIRECTORY_SEPARATOR.$path;
  30.     }
  31.     public function resolveUri($obj, ?string $fieldName null, ?string $className null): ?string
  32.     {
  33.         [$mapping$name] = $this->getFilename($obj$fieldName$className);
  34.         if (empty($name)) {
  35.             return null;
  36.         }
  37.         $uploadDir $this->convertWindowsDirectorySeparator($mapping->getUploadDir($obj));
  38.         $uploadDir = empty($uploadDir) ? '' $uploadDir.'/';
  39.         return \sprintf('%s/%s'$mapping->getUriPrefix(), $uploadDir.$name);
  40.     }
  41.     private function convertWindowsDirectorySeparator(string $string): string
  42.     {
  43.         return \str_replace('\\''/'$string);
  44.     }
  45. }