Ejemplo n.º 1
0
 /**
  * @param string $name
  * @return string
  */
 protected function normalize($name)
 {
     // Strip m:n delimiters
     $name = Helpers::stripMnDelimiters($name, '_');
     // Convert to camelCase
     $name = Helpers::camelCase($name);
     return $name;
 }
Ejemplo n.º 2
0
 /**
  * @param PhpNamespace $namespace
  * @param ClassType $class
  * @param Column $column
  * @return void
  */
 public function doDecorate(Column $column, ClassType $class, PhpNamespace $namespace)
 {
     $column->setPhpDoc($doc = new PhpDoc());
     // Annotation
     $doc->setAnnotation('@property');
     // Type
     if ($column->isNullable()) {
         $doc->setType($this->getRealType($column) . '|NULL');
     } else {
         $doc->setType($this->getRealType($column));
     }
     // Variable
     $doc->setVariable(Helpers::camelCase($column->getName()));
     // Defaults
     if ($column->getDefault() !== NULL) {
         $doc->setDefault($this->getRealDefault($column));
     }
     // Enum
     if (!empty($enum = $column->getEnum())) {
         $doc->setEnum(Strings::upper($column->getName()));
     }
     // Relations
     if (($key = $column->getForeignKey()) !== NULL) {
         // Find foreign entity table
         $ftable = $column->getTable()->getDatabase()->getForeignTable($key->getReferenceTable());
         // Update type to Entity name
         $doc->setType($this->resolver->resolveEntityName($ftable));
         $doc->setRelation($relDoc = new PhpRelDoc());
         if ($use = $this->getRealUse($ftable, $namespace)) {
             $namespace->addUse($use);
         }
         $relDoc->setType('???');
         $relDoc->setEntity($this->resolver->resolveEntityName($ftable));
         $relDoc->setVariable('???');
     }
     // Append phpDoc to class
     $class->addDocument((string) $column->getPhpDoc());
 }
Ejemplo n.º 3
0
 /**
  * @param Table $table
  */
 protected function analyseColumns(Table $table)
 {
     $tableName = $table->getName();
     // Analyse columns
     $columns = $this->driver->getColumns($tableName);
     foreach ($columns as $key => $col) {
         $column = new Column();
         $column->setName($col['name']);
         $column->setNullable($col['nullable']);
         $column->setType(Helpers::columnType($col['nativetype']));
         $column->setDefault($col['default']);
         $column->setOnUpdate(Strings::contains($col['vendor']['Extra'], 'on update'));
         // Analyse ENUM
         if ($col['nativetype'] === ColumnTypes::NATIVE_TYPE_ENUM) {
             $enum = Strings::matchAll($col['vendor']['Type'], ColumnTypes::NATIVE_REGEX_ENUM, PREG_PATTERN_ORDER);
             if ($enum) {
                 $column->setEnum($enum[1]);
                 $column->setType(ColumnTypes::TYPE_ENUM);
                 $column->setSubType(Helpers::columnType($col['nativetype']));
             }
         }
         $table->addColumn($column);
     }
 }