1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
8
|
|
|
use function sprintf; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @todo guilhermeblanco Add constructor requiring tableName and optional schemaName |
12
|
|
|
*/ |
13
|
|
|
class TableMetadata |
14
|
|
|
{ |
15
|
|
|
/** @var string|null */ |
16
|
|
|
protected $schema; |
17
|
|
|
|
18
|
|
|
/** @var string|null */ |
19
|
|
|
protected $name; |
20
|
|
|
|
21
|
|
|
/** @var mixed[] */ |
22
|
|
|
protected $options = []; |
23
|
|
|
|
24
|
|
|
/** @var mixed[][] */ |
25
|
|
|
protected $indexes = []; |
26
|
|
|
|
27
|
|
|
/** @var mixed[][] */ |
28
|
|
|
protected $uniqueConstraints = []; |
29
|
|
|
|
30
|
442 |
|
public function __construct(?string $name = null, ?string $schema = null) |
31
|
|
|
{ |
32
|
442 |
|
$this->name = $name; |
33
|
442 |
|
$this->schema = $schema; |
34
|
442 |
|
} |
35
|
|
|
|
36
|
14 |
|
public function getSchema() : ?string |
37
|
|
|
{ |
38
|
14 |
|
return $this->schema; |
39
|
|
|
} |
40
|
|
|
|
41
|
8 |
|
public function setSchema(string $schema) : void |
42
|
|
|
{ |
43
|
8 |
|
$this->schema = $schema; |
44
|
8 |
|
} |
45
|
|
|
|
46
|
413 |
|
public function setName(string $name) : void |
47
|
|
|
{ |
48
|
413 |
|
$this->name = $name; |
49
|
413 |
|
} |
50
|
|
|
|
51
|
1606 |
|
public function getName() : ?string |
52
|
|
|
{ |
53
|
1606 |
|
return $this->name; |
54
|
|
|
} |
55
|
|
|
|
56
|
1367 |
|
public function getQuotedQualifiedName(AbstractPlatform $platform) : string |
57
|
|
|
{ |
58
|
1367 |
|
if (! $this->schema) { |
59
|
1361 |
|
return $platform->quoteIdentifier($this->name); |
60
|
|
|
} |
61
|
|
|
|
62
|
6 |
|
$separator = ( ! $platform->supportsSchemas() && $platform->canEmulateSchemas()) ? '__' : '.'; |
63
|
|
|
|
64
|
6 |
|
return $platform->quoteIdentifier(sprintf('%s%s%s', $this->schema, $separator, $this->name)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return mixed[] |
69
|
|
|
*/ |
70
|
262 |
|
public function getOptions() : array |
71
|
|
|
{ |
72
|
262 |
|
return $this->options; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param mixed[] $options |
77
|
|
|
*/ |
78
|
|
|
public function setOptions(array $options) : void |
79
|
|
|
{ |
80
|
|
|
$this->options = $options; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
|
|
public function getOption(string $name) |
87
|
|
|
{ |
88
|
|
|
return $this->options[$name]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function hasOption(string $name) : bool |
92
|
|
|
{ |
93
|
|
|
return isset($this->options[$name]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param mixed $value |
98
|
|
|
*/ |
99
|
7 |
|
public function addOption(string $name, $value) : void |
100
|
|
|
{ |
101
|
7 |
|
$this->options[$name] = $value; |
102
|
7 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return mixed[][] |
106
|
|
|
*/ |
107
|
264 |
|
public function getIndexes() : array |
108
|
|
|
{ |
109
|
264 |
|
return $this->indexes; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return mixed[] |
114
|
|
|
*/ |
115
|
|
|
public function getIndex(string $name) : array |
116
|
|
|
{ |
117
|
|
|
return $this->indexes[$name]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function hasIndex(string $name) : bool |
121
|
|
|
{ |
122
|
|
|
return isset($this->indexes[$name]); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param mixed[] $index |
127
|
|
|
*/ |
128
|
18 |
|
public function addIndex(array $index) : void |
129
|
|
|
{ |
130
|
18 |
|
if (! isset($index['name'])) { |
131
|
8 |
|
$this->indexes[] = $index; |
132
|
|
|
|
133
|
8 |
|
return; |
134
|
|
|
} |
135
|
|
|
|
136
|
16 |
|
$this->indexes[$index['name']] = $index; |
137
|
16 |
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return mixed[][] |
141
|
|
|
*/ |
142
|
262 |
|
public function getUniqueConstraints() : array |
143
|
|
|
{ |
144
|
262 |
|
return $this->uniqueConstraints; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return mixed[] |
149
|
|
|
*/ |
150
|
|
|
public function getUniqueConstraint(string $name) : array |
151
|
|
|
{ |
152
|
|
|
return $this->uniqueConstraints[$name]; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function hasUniqueConstraint(string $name) : bool |
156
|
|
|
{ |
157
|
|
|
return isset($this->uniqueConstraints[$name]); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param mixed[] $constraint |
162
|
|
|
*/ |
163
|
10 |
|
public function addUniqueConstraint(array $constraint) : void |
164
|
|
|
{ |
165
|
10 |
|
if (! isset($constraint['name'])) { |
166
|
|
|
$this->uniqueConstraints[] = $constraint; |
167
|
|
|
|
168
|
|
|
return; |
169
|
|
|
} |
170
|
|
|
|
171
|
10 |
|
$this->uniqueConstraints[$constraint['name']] = $constraint; |
172
|
10 |
|
} |
173
|
|
|
} |
174
|
|
|
|