Ejemplo n.º 1
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     /** @var $entity File */
     $entity = $args->getEntity();
     if ($entity instanceof File && $entity->isUploaded()) {
         $this->manager->upload($entity);
         $this->manager->checkOnDelete($entity, $args->getEntityManager());
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     $result = null;
     $entity = $this->attachmentManager->prepareRemoteFile($data);
     if ($entity) {
         $violations = $this->validator->validate($context['entityName'], $entity, $context['fieldName']);
         if (!$violations->count()) {
             $this->attachmentManager->upload($entity);
             $result = $entity;
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 public function testUpload()
 {
     $this->attachment->setEmptyFile(false);
     $file = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\File\\File')->setConstructorArgs([__DIR__ . '/../Fixtures/testFile/test.txt'])->getMock();
     $this->attachment->setFile($file);
     $path = __DIR__ . '/../Fixtures/testFile/test.txt';
     $file->expects($this->once())->method('getPathname')->will($this->returnValue(realpath($path)));
     $file->expects($this->once())->method('isFile')->will($this->returnValue(true));
     $memoryBuffer = new InMemoryBuffer($this->filesystem, 'test.txt');
     $this->filesystem->expects($this->once())->method('createStream')->with($this->attachment->getFilename())->will($this->returnValue($memoryBuffer));
     $this->attachmentManager->upload($this->attachment);
     $memoryBuffer->open(new StreamMode('rb+'));
     $memoryBuffer->seek(0);
     $this->assertEquals('Test data', $memoryBuffer->read(100));
 }