コード例 #1
0
 public function listColumns(Table $table, Schema $schema = null)
 {
     $result = [];
     $schemaFilter = 'DATABASE()';
     if ($schema !== null) {
         $schemaFilter = '\'' . $schema->getName() . '\'';
     }
     $factory = new DataTypeFactory();
     $statement = '
       SELECT
         *
       FROM information_schema.COLUMNS
       WHERE
         TABLE_SCHEMA = ' . $schemaFilter . ' AND
         TABLE_NAME = \'' . $table->getName() . '\'
       ORDER BY ORDINAL_POSITION
     ';
     $rows = $this->connection->execute($statement);
     foreach ($rows->all() as $row) {
         $type = $factory->parseSQLType($row['COLUMN_TYPE']);
         if ($type === null) {
             throw new \RuntimeException(sprintf('Unknown column type "%s" for column "%s".', $row['COLUMN_TYPE'], $row['COLUMN_NAME']));
         }
         $column = new Column($row['COLUMN_NAME'], $type, $row['IS_NULLABLE'] == 'YES');
         if ($row['IS_NULLABLE'] && $row['COLUMN_DEFAULT'] !== null) {
             $column->setDefaultValue($row['COLUMN_DEFAULT']);
         }
         if ($row['EXTRA'] == 'auto_increment') {
             $column->setAutoincrement();
         }
         $column->setComment($row['COLUMN_COMMENT']);
         $result[] = $column;
     }
     return $result;
 }
コード例 #2
0
 public function define($entityClass)
 {
     if (!isset($this->definitions[$entityClass])) {
         return;
     }
     $entity = array_merge(self::$entityDefaults, $this->definitions[$entityClass]);
     $properties = [];
     foreach ($entity['properties'] as $data) {
         $data = array_merge(self::$propertyDefaults, $data);
         $dataType = $this->dataTypeFactory->build($data['type'], $data);
         $column = new Column($data['column'], $dataType, $data['nullable']);
         if ($data['default'] != null) {
             $column->setDefaultValue($data['default']);
         }
         $properties[] = $this->propertyFactory->build($column);
     }
     return $this->entityFactory->build($entityClass, $entity['table'], $properties, $entity['id']);
 }