コード例 #1
0
 protected function setDataStorageObjectMapping($obj, $propertyMapping)
 {
     $class = new \ReflectionClass($obj);
     $this->dataStorage->expects($this->once())->method('getObjectFromArgs')->will($this->returnValue($obj));
     $this->dataStorage->expects($this->once())->method('getReflectionClass')->with($obj)->will($this->returnValue($class));
     $this->propertyMappingfactory->expects($this->once())->method('getMappingsFromObject')->with($obj, $class)->will($this->returnValue(array($propertyMapping)));
 }
コード例 #2
0
ファイル: UploaderListener.php プロジェクト: khasinski/Iphp
 /**
  * Removes the file if necessary.
  *
  * @param \Doctrine\ORM\Event\LifecycleEventArgs $args The event arguments.
  */
 public function postRemove(LifecycleEventArgs $args)
 {
     $mappings = $this->mappingFactory->fromEventArgs($args);
     foreach ($mappings as $mapping) {
         $this->fileStorage->removeByMapping($mapping);
     }
 }
コード例 #3
0
 public function preBind(FormEvent $event)
 {
     $form = $event->getForm();
     $propertyName = $form->getName();
     $obj = $form->getParent()->getData();
     //For oneToMany at SonataAdmin
     if (!$obj) {
         return;
     }
     $mapping = $this->mappingFactory->getMappingFromField($obj, $this->dataStorage->getReflectionClass($obj), $propertyName);
     if ($mapping) {
         /*        $form->add('file', 'file', array('required' => false))
                   ->add('delete', 'checkbox', array('required' => false));*/
         $this->transformer->setMapping($mapping, $mapping->getFileUploadPropertyName() == $propertyName ? FileDataTransformer::MODE_UPLOAD_FIELD : FileDataTransformer::MODE_FILEDATA_FIELD);
     }
 }
コード例 #4
0
 function testPreBind()
 {
     $obj = new DummyEntity();
     $class = new \ReflectionClass($obj);
     $formEvent = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $parentForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $formEvent->expects($this->once())->method('getForm')->will($this->returnValue($form));
     $form->expects($this->once())->method('getParent')->will($this->returnValue($parentForm));
     $parentForm->expects($this->once())->method('getData')->will($this->returnValue($obj));
     $this->dataStorage->expects($this->once())->method('getReflectionClass')->with($obj)->will($this->returnValue($class));
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $this->propertyMappingFactory->expects($this->once())->method('getMappingFromField')->with($obj, $class, 'file')->will($this->returnValue($propertyMapping));
     $form->expects($this->once())->method('getName')->will($this->returnValue('file'));
     $this->transformer->expects($this->once())->method('setMapping')->with($propertyMapping);
     $this->subscriber->preBind($formEvent);
 }
コード例 #5
0
 /**
  * Получить список полей типа
  * iphp_file с описанием связей
  * @param $entity
  * @return PropertyMapping[]
  */
 protected function getFileMappings($entity)
 {
     if (!is_null($this->fileMappingCache)) {
         return $this->fileMappingCache;
     }
     $mappings = $this->mappingFactory->getMappingsFromObject($entity, new \ReflectionClass(get_class($entity)));
     $properties = [];
     foreach ($mappings as $mapping) {
         $properties[$mapping->getFileUploadPropertyName()] = $mapping;
     }
     return $this->fileMappingCache = $properties;
 }
コード例 #6
0
 /**
  * Checks for for file to upload and store it for store at postFlush event
  *
  * @param \Doctrine\Common\EventArgs $args The event arguments.
  */
 public function prePersist(EventArgs $args)
 {
     $obj = $this->dataStorage->getObjectFromArgs($args);
     $mappings = $this->mappingFactory->getMappingsFromObject($obj, $this->dataStorage->getReflectionClass($obj));
     $curFiles = new \SplObjectStorage();
     foreach ($mappings as $mapping) {
         $file = $mapping->getFileUploadPropertyValue();
         if ($file instanceof File) {
             $curFiles[$mapping] = $file;
         }
         $mapping->setFileUploadPropertyValue(null);
     }
     //if ($curFiles) $this->deferredFiles [$mappings[0]->getObj()] = $curFiles;
     if (count($curFiles)) {
         $this->deferredFiles[$obj] = $curFiles;
     }
 }
コード例 #7
0
 public function testConfiguredNamerRetrievedFromInvoker()
 {
     $obj = new DummyEntity();
     $class = new \ReflectionClass($obj);
     $mappingsConfig = array('dummy_file' => array('upload_dir' => '/www/web/images', 'upload_path' => '/images', 'namer' => array('translit' => array('service' => 'iphp.filestore.namer.default'))));
     $uploadable = Mocks::getUploadableMock($this);
     $fileField = Mocks::getUploadableFieldMock($this);
     $fileField->expects($this->any())->method('getMapping')->will($this->returnValue('dummy_file'));
     $fileField->expects($this->once())->method('getFileUploadPropertyName')->will($this->returnValue('file'));
     $fileField->expects($this->once())->method('getFileDataPropertyName')->will($this->returnValue('file'));
     $this->driver->expects($this->once())->method('readUploadable')->with($class)->will($this->returnValue($uploadable));
     $this->driver->expects($this->once())->method('readUploadableFields')->with($class)->will($this->returnValue(array($fileField)));
     $factory = new PropertyMappingFactory($this->namerServiceInvoker, $this->driver, $mappingsConfig);
     $mappings = $factory->getMappingsFromObject($obj, $class);
     $this->assertEquals(1, count($mappings));
     if (count($mappings) > 0) {
         $mapping = $mappings[0];
         $this->namerServiceInvoker->expects($this->once())->method('rename')->with('iphp.filestore.namer.default', 'translit', $mapping, 'ab cde', array())->will($this->returnValue('ab-cde'));
         $this->assertEquals($mapping->useFileNamer('ab cde'), 'ab-cde');
         $this->assertTrue($mapping->hasNamer());
     }
 }