Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c6096c2

Browse files
committedJun 18, 2025
Handle new version dbal doctrine
1 parent 2d0631a commit c6096c2

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed
 

‎src/Data/Schema.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,45 @@ public function getData()
2020

2121
$this->collections = [];
2222
foreach ($tables as $table) {
23-
$columns = $schema->listTableColumns($table);
24-
$foreignKeys = collect($schema->listTableForeignKeys($table))->keyBy(function ($foreignColumn) {
25-
return $foreignColumn->getLocalColumns()[0];
23+
$columns = method_exists($schema, 'listTableColumns')
24+
? $schema->listTableColumns($table)
25+
: $schema->getColumns($table);
26+
$foreignKeys = collect(
27+
method_exists($schema, 'listTableForeignKeys')
28+
? $schema->listTableForeignKeys($table)
29+
: $schema->getForeignKeys($table)
30+
)->keyBy(function ($foreignColumn) {
31+
if (is_object($foreignColumn) && method_exists($foreignColumn, 'getLocalColumns')) {
32+
return $foreignColumn->getLocalColumns()[0];
33+
}
34+
35+
return data_get($foreignColumn, 'columns.0');
2636
});
2737

2838
foreach ($columns as $column) {
29-
$columnName = $column->getName();
30-
$columnType = $column->getType()->getName();
39+
$columnName = is_object($column) && method_exists($column, 'getName') ? $column->getName() : data_get($column, 'name');
40+
$columnType = is_object($column) && method_exists($column, 'getType') ? $column->getType()->getName() : data_get($column, 'type_name');
3141
if (isset($foreignKeys[$columnName])) {
3242
$foreignColumn = $foreignKeys[$columnName];
33-
$foreignTable = $foreignColumn->getForeignTableName();
43+
$foreignTable = is_object($foreignColumn) && method_exists($foreignColumn, 'getForeignTableName')
44+
? $foreignColumn->getForeignTableName()
45+
: data_get($foreignColumn, 'foreign_table');
3446
$columnType = 'FK -> '.$foreignTable;
3547
}
36-
$length = $column->getLength();
48+
$length = is_object($column) && method_exists($column, 'getLength') ? $column->getLength() : count($columns);
3749

3850
$details['column'] = $columnName;
3951
$details['type'] = $columnType.$this->determineUnsigned($column);
4052
$details['length'] = $length != 0 ? $length : null;
4153
$details['default'] = $this->getDefaultValue($column);
42-
$details['nullable'] = $this->getExpression(! $column->getNotNull() === true);
43-
$details['comment'] = $column->getComment();
54+
$details['nullable'] = $this->getExpression(
55+
is_object($column) && method_exists($column, 'getNotNull')
56+
? ! $column->getNotNull() === true
57+
: ! data_get($column, 'nullable')
58+
);
59+
$details['comment'] = is_object($column) && method_exists($column, 'getComment')
60+
? $column->getComment()
61+
: data_get($column, 'comment');
4462

4563
$this->collections[$table][] = $details;
4664
}
@@ -51,16 +69,26 @@ public function getData()
5169

5270
private function determineUnsigned($column)
5371
{
54-
return ($column->getUnsigned() === true) ? '(unsigned)' : '';
72+
if (is_object($column) && method_exists($column, 'getUnsigned')) {
73+
return ($column->getUnsigned() === true) ? '(unsigned)' : '';
74+
}
75+
76+
return str_contains(
77+
data_get($column, 'type'), 'unsigned'
78+
) === true ? '(unsigned)' : '';
5579
}
5680

5781
private function getDefaultValue($column)
5882
{
59-
if ($column->getType()->getName() == 'boolean') {
83+
if (is_object($column) && method_exists($column, 'getType') && $column->getType()->getName() == 'boolean') {
6084
return $column->getDefault() ? 'true' : 'false';
6185
}
6286

63-
return $column->getDefault();
87+
if (is_object($column) && method_exists($column, 'getDefault')) {
88+
return $column->getDefault();
89+
}
90+
91+
return data_get($column, 'default') ? 'true' : 'false';
6492
}
6593

6694
private function getExpression($status)

‎src/Processor.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,21 @@ public function connect(string $database_connection, string $format): self
5858

5959
throw_if(! class_exists($this->presenter), 'RuntimeException', "$this->presenter not exists.");
6060

61-
$this->connection = DB::connection($this->database_connection)->getDoctrineConnection();
62-
$this->schema = $this->connection->createSchemaManager();
63-
$this->tables = $this->schema->listTableNames();
61+
$this->connection = DB::connection($this->database_connection);
62+
63+
if (method_exists($this->connection, 'getDoctrineConnection')) {
64+
$this->connection = $this->connection->getDoctrineConnection();
65+
$this->schema = $this->connection->createSchemaManager();
66+
$this->tables = $this->schema->listTableNames();
67+
} else {
68+
$schemaBuilder = $this->connection->getSchemaBuilder();
69+
$tables = method_exists($schemaBuilder, 'getTables')
70+
? $schemaBuilder->getTables()
71+
: [];
72+
73+
$this->tables = array_column($tables, 'name');
74+
$this->schema = $schemaBuilder;
75+
}
6476

6577
return $this;
6678
}

0 commit comments

Comments
 (0)
Please sign in to comment.