/** * Creates a property mapping object which contains the * configuration for the specified uploadable field. * * @param object $obj The object. * @param \ReflectionClass $class * @param string $field entity field name * @param bool $allFields search all fields (if upload field and file data field are separate) * @return null|\Iphp\FileStoreBundle\Mapping\PropertyMapping The property mapping. */ public function getMappingFromField($obj, \ReflectionClass $class, $field, $allFields = true) { if (!$this->hasAnnotations($class)) { return null; } $annotation = $this->driver->readUploadableField($class, $field); if (!$annotation && $allFields) { $propertyAnnotations = $this->driver->readUploadableFields($class); foreach ($propertyAnnotations as $propertyAnnotation) { if ($propertyAnnotation->getFileDataPropertyName() == $field || $propertyAnnotation->getFileUploadPropertyName() == $field) { $annotation = $propertyAnnotation; break; } } } if (null === $annotation) { return null; } return $this->createMapping($obj, $class, $annotation); }
/** * Creates a property mapping object which contains the * configuration for the specified uploadable field. * * @param object $obj The object. * @param string $field The field. * @return null|\Iphp\FileStoreBundle\Mapping\PropertyMapping The property mapping. */ public function fromField($obj, $field) { $class = $this->dataStorage->getReflectionClass($obj); if (!$this->hasAnnotations($class)) { return null; } $annot = $this->driver->readUploadableField($class, $field); if (null === $annot) { return null; } return $this->createMapping($obj, $annot); }
/** * Tests that the driver correctly reads one UploadableField * property. */ public function testReadUploadableFieldNoMapping() { $uploadableField = Mocks::getUploadableFieldMock($this); $uploadableField->expects($this->never())->method('setPropertyName'); $entity = new DummyEntity(); $class = new \ReflectionClass($entity); $reader = $this->getMock('Doctrine\\Common\\Annotations\\Reader'); $reader->expects($this->any())->method('getPropertyAnnotation')->will($this->returnCallback(function () use($uploadableField) { $args = func_get_args(); if ('file' === $args[0]->getName()) { return null; } return null; })); $driver = new AnnotationDriver($reader); $this->assertEquals($driver->readUploadableField($class, 'file'), null); }