/**
  * Read the entity and create an associated metadata
  * @param $entity
  * @return null|FormMetadata
  */
 public function getMetadata($entity)
 {
     $metadata = new FormMetadata();
     $metadataTop = new FormMetadata();
     $metadataChildren = new FormMetadata();
     /** @var @var ReflectionClass $reflectionClass */
     $reflectionClass = new \ReflectionClass(get_class($entity));
     // retrieve all form fields for the main entity class and it's parents
     while (is_object($reflectionClass)) {
         $metadataTop = $this->getClassFormFields($reflectionClass);
         $reflectionClass = $reflectionClass->getParentClass();
         $metadata->merge($metadataTop);
     }
     // retrieve all subsequent nested classes' form fields and their parents
     $fieldEntities = $metadata->getFieldEntities();
     if (!empty($fieldEntities)) {
         foreach ($fieldEntities as $key => $fieldEntity) {
             $class = $fieldEntity->getClass();
             $reflectionClass = new \ReflectionClass($class);
             while (is_object($reflectionClass)) {
                 $fieldEntityFields = $this->getClassFormFields($reflectionClass);
                 $fieldEntity->setFields($fieldEntityFields->getFields());
                 //$reflectionClass = $reflectionClass->getParentClass();
                 $reflectionClass = null;
             }
             //$metadata->merge($metadataChildren);
         }
     }
     return $metadata;
 }
Пример #2
0
 /**
  * @param FormMetadata $refObject
  * @return void
  */
 public function merge(FormMetadata $refObject)
 {
     $this->fields = array_merge($this->fields, $refObject->getFields());
     $this->groups = array_merge($this->groups, $refObject->getGroups());
     $this->formTypes = array_merge($this->formTypes, $refObject->getFormTypes());
     $this->fieldEntities = array_merge($this->fieldEntities, $refObject->getFieldEntities());
 }