build() public static method

public static build ( DataType $component, array $options = [] ) : string
$component DataType The component to be built.
$options array Parameters for building.
return string
Ejemplo n.º 1
0
 /**
  * @return string
  */
 public function build()
 {
     $fields = '';
     if (!empty($this->fields)) {
         if (is_array($this->fields)) {
             $fields = CreateDefinition::build($this->fields) . ' ';
         } elseif ($this->fields instanceof ArrayObj) {
             $fields = ArrayObj::build($this->fields);
         }
     }
     if ($this->options->has('DATABASE')) {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . OptionsArray::build($this->entityOptions);
     } elseif ($this->options->has('TABLE')) {
         $partition = '';
         if (!empty($this->partitionBy)) {
             $partition .= "\nPARTITION BY " . $this->partitionBy;
         }
         if (!empty($this->partitionsNum)) {
             $partition .= "\nPARTITIONS " . $this->partitionsNum;
         }
         if (!empty($this->subpartitionBy)) {
             $partition .= "\nSUBPARTITION BY " . $this->subpartitionBy;
         }
         if (!empty($this->subpartitionsNum)) {
             $partition .= "\nSUBPARTITIONS " . $this->subpartitionsNum;
         }
         if (!empty($this->partitions)) {
             $partition .= "\n" . PartitionDefinition::build($this->partitions);
         }
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . $fields . OptionsArray::build($this->entityOptions) . $partition;
     } elseif ($this->options->has('VIEW')) {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . $fields . ' AS ' . TokensList::build($this->body) . ' ' . OptionsArray::build($this->entityOptions);
     } elseif ($this->options->has('TRIGGER')) {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . OptionsArray::build($this->entityOptions) . ' ' . 'ON ' . Expression::build($this->table) . ' ' . 'FOR EACH ROW ' . TokensList::build($this->body);
     } elseif ($this->options->has('PROCEDURE') || $this->options->has('FUNCTION')) {
         $tmp = '';
         if ($this->options->has('FUNCTION')) {
             $tmp = 'RETURNS ' . DataType::build($this->return);
         }
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . ParameterDefinition::build($this->parameters) . ' ' . $tmp . ' ' . TokensList::build($this->body);
     } else {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . TokensList::build($this->body);
     }
     return '';
 }
Ejemplo n.º 2
0
 /**
  * @param FieldDefinition|FieldDefinition[] $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     if (is_array($component)) {
         $ret = array();
         foreach ($component as $c) {
             $ret[] = static::build($c);
         }
         return "(\n" . implode(",\n", $ret) . "\n)";
     } else {
         $tmp = '';
         if ($component->isConstraint) {
             $tmp .= 'CONSTRAINT ';
         }
         if (!empty($component->name)) {
             $tmp .= Context::escape($component->name) . ' ';
         }
         if (!empty($component->type)) {
             $tmp .= DataType::build($component->type) . ' ';
         }
         if (!empty($component->key)) {
             $tmp .= Key::build($component->key) . ' ';
         }
         if (!empty($component->references)) {
             $tmp .= 'REFERENCES ' . Reference::build($component->references) . ' ';
         }
         $tmp .= OptionsArray::build($component->options);
         return trim($tmp);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param CreateDefinition|CreateDefinition[] $component The component to be built.
  * @param array                               $options   Parameters for building.
  *
  * @return string
  */
 public static function build($component, array $options = array())
 {
     if (is_array($component)) {
         return "(\n  " . implode(",\n  ", $component) . "\n)";
     } else {
         $tmp = '';
         if ($component->isConstraint) {
             $tmp .= 'CONSTRAINT ';
         }
         if (isset($component->name) && $component->name !== '') {
             $tmp .= Context::escape($component->name) . ' ';
         }
         if (!empty($component->type)) {
             $tmp .= DataType::build($component->type, array('lowercase' => true)) . ' ';
         }
         if (!empty($component->key)) {
             $tmp .= $component->key . ' ';
         }
         if (!empty($component->references)) {
             $tmp .= 'REFERENCES ' . $component->references . ' ';
         }
         $tmp .= $component->options;
         return trim($tmp);
     }
 }
 /**
  * @param ParameterDefinition[] $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     $ret = array();
     foreach ($component as $c) {
         $tmp = '';
         if (!empty($c->inOut)) {
             $tmp .= $c->inOut . ' ';
         }
         $ret[] = trim($tmp . Context::escape($c->name) . ' ' . DataType::build($c->type));
     }
     return '(' . implode(', ', $ret) . ')';
 }