6
6
7
7
use Doctrine \DBAL \Exception ;
8
8
use Doctrine \DBAL \Schema \Column ;
9
- use Doctrine \DBAL \Types \Types ;
10
9
use Illuminate \Database \Eloquent \Model ;
11
10
use Orion \ValueObjects \Specs \Schema \Properties \AnySchemaProperty ;
12
11
use Orion \ValueObjects \Specs \Schema \Properties \ArraySchemaProperty ;
@@ -27,61 +26,68 @@ class SchemaManager
27
26
public function getSchemaColumns (Model $ resourceModel ): array
28
27
{
29
28
$ table = $ resourceModel ->getConnection ()->getTablePrefix ().$ resourceModel ->getTable ();
30
- $ schema = $ resourceModel ->getConnection ()->getDoctrineSchemaManager ();
31
-
32
- $ databasePlatform = $ schema ->getDatabasePlatform ();
33
- $ databasePlatform ->registerDoctrineTypeMapping ('enum ' , 'string ' );
34
29
35
30
$ database = null ;
31
+
36
32
if (strpos ($ table , '. ' )) {
37
33
[$ database , $ table ] = explode ('. ' , $ table );
38
34
}
39
35
40
- return $ schema ->listTableColumns ($ table , $ database ) ?? [];
36
+ if ((float ) app ()->version () < 11.0 ) {
37
+ $ schema = $ resourceModel ->getConnection ()->getDoctrineSchemaManager ();
38
+
39
+ $ databasePlatform = $ schema ->getDatabasePlatform ();
40
+ $ databasePlatform ->registerDoctrineTypeMapping ('enum ' , 'string ' );
41
+
42
+ return collect ($ schema ->listTableColumns ($ table , $ database ))->map (function (Column $ column ) {
43
+ return [
44
+ 'name ' => $ column ->getName (),
45
+ 'type ' => $ column ->getType ()->getName (),
46
+ 'nullable ' => !$ column ->getNotnull ()
47
+ ];
48
+ })->toArray ();
49
+ }
50
+
51
+ return $ resourceModel ->getConnection ()->getSchemaBuilder ()->getColumns ($ table );
41
52
}
42
53
43
54
/**
44
- * @param Column $column
55
+ * @param array $column
45
56
* @param Model $resourceModel
46
57
* @return string
47
58
*/
48
- public function resolveSchemaPropertyClass (Column $ column , Model $ resourceModel ): string
59
+ public function resolveSchemaPropertyClass (array $ column , Model $ resourceModel ): string
49
60
{
50
- if (in_array ($ column-> getName () , $ resourceModel ->getDates (), true )) {
61
+ if (in_array ($ column[ ' name ' ] , $ resourceModel ->getDates (), true )) {
51
62
return DateTimeSchemaProperty::class;
52
63
}
53
64
54
- switch ($ column ->getType ()->getName ()) {
55
- case Types::BIGINT :
56
- case Types::INTEGER :
57
- case Types::SMALLINT :
65
+ switch ($ column ['type ' ]) {
66
+ case strpos ($ column ['type ' ], 'int ' ) !== false :
58
67
return IntegerSchemaProperty::class;
59
- case Types:: FLOAT :
60
- case Types:: DECIMAL :
68
+ case ' float ' :
69
+ case ' decimal ' :
61
70
return NumberSchemaProperty::class;
62
- case Types:: BOOLEAN :
71
+ case strpos ( $ column [ ' type ' ], ' bool ' ) !== false :
63
72
return BooleanSchemaProperty::class;
64
- case Types::STRING :
65
- case Types::TEXT :
66
- case Types::ASCII_STRING :
67
- case Types::GUID :
68
- case Types::TIME_MUTABLE :
69
- case Types::TIME_IMMUTABLE :
73
+ case strpos ($ column ['type ' ], 'char ' ) !== false :
74
+ case strpos ($ column ['type ' ], 'time ' ) !== false :
75
+ case 'text ' :
76
+ case 'string ' :
77
+ case 'guid ' :
70
78
return StringSchemaProperty::class;
71
- case Types:: DATE_MUTABLE :
72
- case Types:: DATE_IMMUTABLE :
79
+ case ' date ' :
80
+ case ' date_immutable ' :
73
81
return DateSchemaProperty::class;
74
- case Types:: DATETIME_MUTABLE :
75
- case Types:: DATETIME_IMMUTABLE :
82
+ case ' datetime ' :
83
+ case ' datetime_immutable ' :
76
84
return DateTimeSchemaProperty::class;
77
- case Types::ARRAY :
78
- case Types::SIMPLE_ARRAY :
85
+ case 'array ' :
79
86
return ArraySchemaProperty::class;
80
- case Types::OBJECT :
81
- case Types::JSON :
87
+ case strpos ($ column ['type ' ], 'json ' ) !== false :
82
88
return ObjectSchemaProperty::class;
83
- case Types:: BINARY :
84
- case Types:: BLOB :
89
+ case ' binary ' :
90
+ case ' blob ' :
85
91
return BinarySchemaProperty::class;
86
92
default :
87
93
return AnySchemaProperty::class;
0 commit comments