|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Library\Database; |
|
4
|
|
|
|
|
5
|
|
|
final class Table |
|
6
|
|
|
{ |
|
7
|
|
|
private string $name; |
|
8
|
|
|
private array $columns = []; |
|
9
|
|
|
private array $indexes = []; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct(string $name, array $columns = []) |
|
12
|
|
|
{ |
|
13
|
|
|
$this->name = $name; |
|
14
|
|
|
foreach ($columns as $column) { |
|
15
|
|
|
$this->columns[$column['name']] = new class($column) |
|
16
|
|
|
{ |
|
17
|
|
|
public function __construct(private array $column) |
|
18
|
|
|
{ |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function getName() |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->column['name']; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getNotnull() |
|
27
|
|
|
{ |
|
28
|
|
|
return ! $this->column['nullable']; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getDefault() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->column['default']; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getUnsigned() |
|
37
|
|
|
{ |
|
38
|
|
|
return in_array('unsigned', explode(' ', $this->column['type'])); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getType() |
|
42
|
|
|
{ |
|
43
|
|
|
return new class($this->column) |
|
44
|
|
|
{ |
|
45
|
|
|
public function __construct(private array $column) |
|
46
|
|
|
{ |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getName() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->column['type_name']; |
|
52
|
|
|
} |
|
53
|
|
|
}; |
|
54
|
|
|
} |
|
55
|
|
|
}; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getName(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->name; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getColumns() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->columns; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function hasColumn(string $columnName) |
|
70
|
|
|
{ |
|
71
|
|
|
return isset($this->columns[$columnName]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getColumn(string $columnName) |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->columns[$columnName]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getIndexes() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->indexes; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function setIndexes(array $indexes) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->indexes = $indexes; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|