/** * Creates an array of PropetyMapping objects which contain the * configuration for the uploadable fields in the specified * object. * * @param object $obj The object. * @return \Iphp\FileStoreBundle\Mapping\PropertyMapping[] objects. */ public function fromObject($obj) { $class = $this->dataStorage->getReflectionClass($obj); if (!$this->hasAnnotations($class)) { return array(); } $mappings = array(); foreach ($this->driver->readUploadableFields($class) as $field) { $mappings[] = $this->createMapping($obj, $field); } return $mappings; }
/** * 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); }
/** * Test that the driver reads zero UploadableField * properties when none exist. */ public function testReadNoUploadableFieldsWhenNoneExist() { $entity = new DummyEntity(); $class = new \ReflectionClass($entity); $reader = $this->getMock('Doctrine\\Common\\Annotations\\Reader'); $reader->expects($this->any())->method('getPropertyAnnotation')->will($this->returnValue(null)); $driver = new AnnotationDriver($reader); $fields = $driver->readUploadableFields($class); $this->assertEquals(0, count($fields)); }