Ejemplo n.º 1
0
 /**
  * Builds a FieldDefinition from a property
  * 
  * @param Annotation $annotation
  * @param ReflectionProperty $property
  * @return FieldDefinition
  */
 protected function buildField($annotation, ReflectionProperty $property = null, array $additionalAnnotations = array())
 {
     $field = new FieldDefinition();
     $field->setProperty($annotation->property)->setName($annotation->name ?: $annotation->property)->setDescription($annotation->description)->setType($annotation->type)->setIdentifier($annotation->identifier)->setStringRepr($annotation->repr)->setOptional(!$annotation->required)->setGetterSetterMethodNames($annotation->getter, $annotation->setter);
     if ($annotation->formField !== null) {
         $field->setFormFieldType($annotation->formField);
     }
     if ($annotation->visibility !== null) {
         $field->setVisibility($annotation->visibility);
     }
     if ($property !== null && !$property->isPublic() || $annotation->getter !== null || $annotation->setter !== null) {
         $field->setAccessMethod(FieldDefinition::ACCESS_GETTER_SETTER);
     }
     $this->applyFieldConstraintsFromAnnotations($field, $additionalAnnotations);
     if ($annotation->type === null) {
         if ($property !== null && preg_match('/@var ([a-zA-Z]+)/', $property->getDocComment(), $results)) {
             $field->setType($results[1]);
         } else {
             $field->setType('string');
         }
     }
     return $field;
 }