コード例 #1
0
ファイル: ObjectTrait.php プロジェクト: rougin/wildfire
 /**
  * Sets the foreign field of the column, if any.
  *
  * @param  \CI_Model               $model
  * @param  \Rougin\Describe\Column $column
  * @param  array                   $properties
  * @return void
  */
 protected function setForeignField(\CI_Model $model, Column $column, array $properties)
 {
     $columnName = $column->getField();
     $foreignColumn = $column->getReferencedField();
     $foreignTable = $column->getReferencedTable();
     if (in_array($foreignTable, $properties['belongs_to'])) {
         $delimiters = [$foreignColumn => $model->{$columnName}];
         $foreign = $this->find($foreignTable, $delimiters);
         if (is_object($foreign)) {
             $tableName = TableHelper::getNameFromModel($foreign);
             $model->{$tableName} = $foreign;
         }
     }
 }
コード例 #2
0
ファイル: MySQLDriver.php プロジェクト: rougin/describe
 /**
  * Sets the properties of the specified column.
  *
  * @param  mixed                   $row
  * @param  \Rougin\Describe\Column &$column
  * @return void
  */
 protected function setProperties($row, Column &$column)
 {
     $null = 'Null';
     if ($row->Extra == 'auto_increment') {
         $column->setAutoIncrement(true);
     }
     if ($row->{$null} == 'YES') {
         $column->setNull(true);
     }
 }
コード例 #3
0
ファイル: ModelGenerator.php プロジェクト: rougin/weasley
 /**
  * Sets specified fields for foreign key values.
  * 
  * @param \Rougin\Describe\Column $column
  */
 public function setForeignKey(Column $column, array &$data, array &$keywords)
 {
     if (!$column->isForeignKey()) {
         return;
     }
     $config = Configuration::get();
     $template = $this->foreignColumnTemplate;
     $data['methods'] .= "\n    " . $this->mutatorMethodTemplate . "\n    ";
     $data['methods'] .= $this->accessorMethodTemplate;
     $referencedTable = $this->stripTableSchema($column->getReferencedTable());
     $keywords['{accessorName}'] = Inflector::camelize('get_' . $referencedTable);
     $keywords['{mutatorName}'] = Inflector::camelize('set_' . $referencedTable);
     $keywords['{primaryKey}'] = $this->describe->getPrimaryKey($referencedTable);
     $keywords['{variable}'] = $referencedTable;
     $keywords['{referencedTable}'] = ucfirst($referencedTable);
     $keywords['{description}'] = $referencedTable;
     $keywords['{class}'] = ucfirst($referencedTable) . ' ';
     $keywords['{datatype}'] = '\\' . $config->application->name . '\\' . $config->namespaces->models . '\\' . ucfirst($referencedTable);
     $template = str_replace(array_keys($keywords), array_values($keywords), $template);
     $data['methods'] = str_replace(array_keys($keywords), array_values($keywords), $data['methods']);
     $data['columns'] .= $template;
 }
コード例 #4
0
ファイル: SQLiteDriver.php プロジェクト: rougin/describe
 /**
  * Sets the properties of the specified column.
  *
  * @param  mixed                   $row
  * @param  \Rougin\Describe\Column &$column
  * @return void
  */
 protected function setProperties($row, Column &$column)
 {
     if (!$row->notnull) {
         $column->setNull(true);
     }
     if ($row->pk) {
         $column->setPrimary(true);
         $column->setAutoIncrement(true);
     }
 }
コード例 #5
0
 /**
  * Sets properties for a specified column
  *
  * @param  Column         $column
  * @param  InputInterface $input
  * @return Column
  */
 private function setColumn(Column $column, InputInterface $input)
 {
     $column->setNull($input->getOption('null'));
     $column->setDataType($input->getOption('type'));
     $column->setLength($input->getOption('length'));
     $column->setPrimary($input->getOption('primary'));
     $column->setUnsigned($input->getOption('unsigned'));
     $column->setDefaultValue($input->getOption('default'));
     $column->setAutoIncrement($input->getOption('auto_increment'));
     return $column;
 }