Exemple #1
0
 /**
  * @param Column $col
  * @return array
  */
 protected function colConfig(Column $col)
 {
     $conf = [];
     //var_dump($col->toArray()); //, $col->getType()->getTypesMap());
     $fieldClass = self::$dbType2FieldClass[$col->getType()->getName()];
     $fieldName = $col->getName();
     if ($col->getAutoincrement()) {
         $fieldClass = 'Auto';
     } elseif (substr($col->getName(), -3) === '_id') {
         $fieldClass = 'ForeignKey';
         $fk_tbl = substr($col->getName(), 0, strpos($col->getName(), '_id'));
         $fieldName = $fk_tbl;
         $conf['relationClass'] = $this->table2model($fk_tbl);
         $conf['db_column'] = $col->getName();
         if (!isset($this->generated[$fk_tbl])) {
             $this->generateQueue[] = $fk_tbl;
         }
     }
     array_unshift($conf, $fieldClass);
     if ($this->dp->getReservedKeywordsList()->isKeyword($col->getName())) {
         $conf['db_column'] = 'f_' . $col->getName();
     }
     if ($col->getNotnull() === false) {
         $conf['null'] = true;
     }
     if ($col->getLength() !== null) {
         $conf['max_length'] = $col->getLength();
     }
     if ($col->getDefault() !== null) {
         if ($col->getDefault() !== 'CURRENT_TIMESTAMP') {
             $conf['default'] = $col->getType()->convertToPHPValue($col->getDefault(), $this->dp);
             if ($conf['default'] === '') {
                 $conf['blank'] = true;
             }
         }
     }
     if ($col->getComment() !== null) {
         $help = $col->getComment();
         if (strpos($help, PHP_EOL) !== false) {
             $help = str_replace(PHP_EOL, '', $help);
         }
         $conf['help_text'] = $help;
     }
     return [$fieldName, $conf];
 }
 /**
  * Get the quoted representation of this asset but only if it was defined with one. Otherwise
  * return the plain unquoted value as inserted.
  *
  * @param AbstractPlatform $platform
  * @return string
  */
 public function getQuotedName(AbstractPlatform $platform)
 {
     $keywords = $platform->getReservedKeywordsList();
     $parts = explode(".", $this->getName());
     foreach ($parts as $k => $v) {
         $parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v;
     }
     return implode(".", $parts);
 }
 /**
  * @group DBAL-45
  */
 public function testKeywordList()
 {
     $keywordList = $this->_platform->getReservedKeywordsList();
     $this->assertInstanceOf('Doctrine\\DBAL\\Platforms\\Keywords\\KeywordList', $keywordList);
     $this->assertTrue($keywordList->isKeyword('table'));
 }