Example #1
0
 private function fieldString(Annotation $field)
 {
     $typeMap = array('integer' => 'int', 'string' => 'varchar', 'text' => 'text', 'boolean' => 'tinyint', '\\DateTime' => 'timestamp');
     $generateMap = ['auto' => 'AUTO_INCREMENT'];
     if ($field->getGenerate() && isset($generateMap[$field->getGenerate()])) {
         $generate = $generateMap[$field->getGenerate()];
     } else {
         $generate = '';
     }
     return '`' . $field->getName() . '` ' . strtoupper($typeMap[$field->getType()]) . ($field->getLength() ? ' (' . $field->getLength() . ') ' : '') . $generate;
 }
Example #2
0
 private function parseMetadata()
 {
     /**
      * Table
      */
     $reflection = new \ReflectionClass($this->entityName);
     $this->tableName = $this->tableNameFromName($reflection->getName());
     $classDocComment = new ReflectionDocComment($reflection->getDocComment());
     $this->orderBy = $classDocComment->getAnnotation('orderBy');
     /**
      * Properties
      */
     $properties = array_reverse($reflection->getProperties(\ReflectionProperty::IS_PROTECTED));
     foreach ($properties as $property) {
         /** @var \ReflectionProperty $property */
         $docComment = new ReflectionDocComment($property->getDocComment());
         $joinRelationColumn = $docComment->getAnnotation('joinRelationColumn');
         $relation = null;
         $relationEntityName = null;
         $length = null;
         if ($docComment->getAnnotation('type')) {
             $type = $docComment->getAnnotation('type');
         } else {
             switch ($docComment->getAnnotation('var')) {
                 case '\\DateTime':
                     $type = '\\DateTime';
                     break;
                 case 'boolean':
                 case 'bool':
                     $type = 'boolean';
                     $length = 1;
                     break;
                 case 'integer':
                 case 'int':
                     $type = 'integer';
                     $length = 10;
                     break;
                 case 'string':
                 case null:
                     $type = 'string';
                     $length = 255;
                     break;
                 default:
                     $type = $docComment->getAnnotation('var');
                     if (strpos($type, '[]')) {
                         $relation = 'many';
                         $relationEntityName = str_replace('[]', '', $type);
                         if (empty($joinRelationColumn)) {
                             $joinRelationColumn = strtolower($reflection->getShortName()) . '_id';
                         }
                     } else {
                         $relation = 'one';
                         $relationEntityName = $type;
                     }
             }
         }
         $annotation = new Annotation();
         $annotation->setName($property->getName())->setLabel($docComment->getShortDescription())->setType($type)->setLength($docComment->getAnnotation('length') ?: $length)->setRelation($relation)->setRelationEntityName($relationEntityName)->setJoinTable($docComment->getAnnotation('joinTable'))->setJoinColumn($docComment->getAnnotation('joinColumn'))->setJoinRelationColumn(!empty($joinRelationColumn) ? $joinRelationColumn : null)->setKey($docComment->getAnnotation('key'))->setGenerate($docComment->getAnnotation('generate'));
         $this->metadata[$annotation->getName()] = $annotation;
     }
 }