Пример #1
0
 public function name($entity, PropertyMapping $mapping)
 {
     $this->mapping = $mapping;
     /* @var UploadedFile $file */
     $file = $mapping->getFile($entity);
     $file_name = $file->getClientOriginalName();
     return $this->getRandomFileName($file_name);
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     $name = uniqid();
     if ($extension = $this->getExtension($file)) {
         $name = sprintf('%s.%s', $name, $extension);
     }
     return $name;
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     $name = $file->getClientOriginalName();
     if ($this->transliterate) {
         $name = $this->transliterate($name);
     }
     /** @var $file UploadedFile */
     return uniqid() . '_' . $name;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     /* @var $file UploadedFile */
     $name = sha1(microtime(true) . mt_rand(0, 999));
     if ($extension = $file->guessExtension()) {
         $name = sprintf('%s.%s', $name, $extension);
     }
     return $name;
 }
 /**
  * @param object          $entity
  * @param PropertyMapping $mapping
  *
  * @return string
  */
 public function name($entity, PropertyMapping $mapping)
 {
     $extension = $this->getExtension($mapping->getFile($entity));
     if ($mapping->getUriPrefix()) {
         $namePieces[] = $mapping->getUriPrefix();
     }
     $namePieces[] = sprintf('%s.%s', str_replace('.', '', uniqid('', true)), $extension);
     $name = implode('/', $namePieces);
     return $name;
 }
Пример #6
0
 /**
  * @inheritDoc
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     if ($extension = $this->getExtension($file)) {
         $originalFileName = str_replace(".{$extension}", "", $file->getClientOriginalName());
         $newFileName = trim(preg_replace('/-+/', "-", preg_replace('/[^a-z0-9]/', "-", strtolower($originalFileName))), '-');
         return sprintf('%s.%s', $newFileName, $extension);
     }
     return null;
 }
 /**
  * Construit le nom du fichier à partir de l'objet
  * @param  [type]          $object  [description]
  * @param  PropertyMapping $mapping [description]
  * @return [type]                   [description]
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     $extension = $this->getExtension($file);
     $name = uniqid();
     if (is_null($object->getId())) {
         $name = parent::name($object, $mapping);
     } elseif (!is_null($extension)) {
         $name = $object->getId() . '.' . $extension;
     }
     return $name;
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function name($object, PropertyMapping $mapping)
 {
     /** @var UploadedFile $file */
     $file = $mapping->getFile($object);
     if (is_null($file)) {
         return false;
     }
     $extension = $file->guessExtension();
     if ($extension == 'jpeg') {
         $extension = 'jpg';
     }
     return sprintf('%s.%s', md5(uniqid()), $extension);
 }
 /**
  * Construit le nom du fichier à partir de l'objet
  * @param  [type]          $object  [description]
  * @param  PropertyMapping $mapping [description]
  * @return [type]                   [description]
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     $extension = $this->getExtension($file);
     if (class_exists('\\Doctrine\\ODM\\MongoDB\\Id\\UuidGenerator')) {
         $generator = new \Doctrine\ODM\MongoDB\Id\UuidGenerator();
         $name = $generator->generateV5($generator->generateV4(), php_uname('n'));
     } else {
         $name = uniqid();
     }
     if ($extension = $this->getExtension($file)) {
         $name = sprintf('%s.%s', $name, $extension);
     }
     return $name;
 }
Пример #10
0
 /**
  * {@inheritDoc}
  */
 public function upload($obj, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($obj);
     if ($file === null || !$file instanceof UploadedFile) {
         throw new \LogicException('No uploadable file found');
     }
     // determine the file's name
     if ($mapping->hasNamer()) {
         $name = $mapping->getNamer()->name($obj, $mapping);
     } else {
         $name = $file->getClientOriginalName();
     }
     $mapping->setFileName($obj, $name);
     // determine the file's directory
     $dir = $mapping->getUploadDir($obj);
     $this->doUpload($mapping, $file, $dir, $name);
 }
 /**
  * @inheritDoc
  */
 public function name($object, PropertyMapping $mapping)
 {
     if (empty($this->propertyPath)) {
         throw new \LogicException('The property to use can not be determined. Did you call the configure() method?');
     }
     $file = $mapping->getFile($object);
     try {
         $name = $this->getPropertyValue($object, $this->propertyPath);
     } catch (NoSuchPropertyException $e) {
         throw new NameGenerationException(sprintf('File name could not be generated: property %s does not exist.', $this->propertyPath), $e->getCode(), $e);
     }
     if (empty($name)) {
         throw new NameGenerationException(sprintf('File name could not be generated: property %s is empty.', $this->propertyPath));
     }
     if ($this->transliterate) {
         $name = $this->transliterate($name);
     }
     // append the file extension if there is one
     if ($extension = $this->getExtension($file)) {
         $name = sprintf('%s.%s', $name, $extension);
     }
     return $name;
 }
Пример #12
0
 /**
  * {@inheritDoc}
  */
 public function name($object, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     /** @var $file UploadedFile */
     return uniqid() . '_' . $file->getClientOriginalName();
 }
Пример #13
0
 public function name($object, \Vich\UploaderBundle\Mapping\PropertyMapping $mapping)
 {
     $file = $mapping->getFile($object);
     $extention = $file->guessExtension();
     return uniqid() . '.' . $extention;
 }
Пример #14
0
 protected function hasUploadedFile($obj, PropertyMapping $mapping)
 {
     $file = $mapping->getFile($obj);
     return $file !== null && $file instanceof UploadedFile;
 }
Пример #15
0
 /**
  * @dataProvider propertiesAccessProvider
  */
 public function testPropertiesAreAccessed($object, $file, $fileName)
 {
     $prop = new PropertyMapping('file', 'fileName');
     $this->assertSame($file, $prop->getFile($object));
     $this->assertSame($fileName, $prop->getFileName($object));
 }