1 | <?php |
||
32 | abstract class AbstractEnumType extends Type |
||
33 | { |
||
34 | /** @var string */ |
||
35 | protected $name = ''; |
||
36 | |||
37 | /** |
||
38 | * @var array|mixed[] Array of ENUM Values, where ENUM values are keys and their readable versions are values |
||
39 | * |
||
40 | * @static |
||
41 | */ |
||
42 | protected static $choices = []; |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | * |
||
47 | * @throws InvalidArgumentException |
||
48 | */ |
||
49 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
||
50 | { |
||
51 | if (null === $value) { |
||
52 | return null; |
||
53 | } |
||
54 | |||
55 | if (!isset(static::$choices[$value])) { |
||
56 | throw new InvalidArgumentException(\sprintf('Invalid value "%s" for ENUM "%s".', $value, $this->getName())); |
||
57 | } |
||
58 | |||
59 | return $value; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function convertToPHPValue($value, AbstractPlatform $platform) |
||
80 | |||
81 | /** |
||
82 | * Gets the SQL declaration snippet for a field of this type. |
||
83 | * |
||
84 | * @param mixed[] $fieldDeclaration The field declaration |
||
85 | * @param AbstractPlatform $platform The currently used database platform |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function requiresSQLCommentHint(AbstractPlatform $platform): bool |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function getName(): string |
||
138 | |||
139 | /** |
||
140 | * Get readable choices for the ENUM field. |
||
141 | * |
||
142 | * @static |
||
143 | * |
||
144 | * @return string[] |
||
145 | */ |
||
146 | public static function getChoices(): array |
||
150 | |||
151 | /** |
||
152 | * Get values for the ENUM field. |
||
153 | * |
||
154 | * @static |
||
155 | * |
||
156 | * @return string[] Values for the ENUM field |
||
157 | */ |
||
158 | public static function getValues(): array |
||
162 | |||
163 | /** |
||
164 | * Get random value for the ENUM field. |
||
165 | * |
||
166 | * @static |
||
167 | * |
||
168 | * @return int|string |
||
169 | */ |
||
170 | public static function getRandomValue() |
||
177 | |||
178 | /** |
||
179 | * Get array of ENUM Values, where ENUM values are keys and their readable versions are values. |
||
180 | * |
||
181 | * @static |
||
182 | * |
||
183 | * @return string[] Array of values in readable format |
||
184 | */ |
||
185 | public static function getReadableValues(): array |
||
189 | |||
190 | /** |
||
191 | * Asserts that given choice exists in the array of ENUM values. |
||
192 | * |
||
193 | * @param string $value ENUM value |
||
194 | * |
||
195 | * @throws InvalidArgumentException |
||
196 | */ |
||
197 | public static function assertValidChoice(string $value): void |
||
203 | |||
204 | /** |
||
205 | * Get value in readable format. |
||
206 | * |
||
207 | * @param string $value ENUM value |
||
208 | * |
||
209 | * @static |
||
210 | * |
||
211 | * @return string Value in readable format |
||
212 | */ |
||
213 | public static function getReadableValue(string $value): string |
||
219 | |||
220 | /** |
||
221 | * Check if some string value exists in the array of ENUM values. |
||
222 | * |
||
223 | * @param string $value ENUM value |
||
224 | * |
||
225 | * @static |
||
226 | * |
||
227 | * @return bool |
||
228 | */ |
||
229 | public static function isValueExist(string $value): bool |
||
233 | |||
234 | /** |
||
235 | * Get default value for DDL statement. |
||
236 | * |
||
237 | * @static |
||
238 | * |
||
239 | * @return string|null Default value for DDL statement |
||
240 | */ |
||
241 | public static function getDefaultValue(): ?string |
||
245 | |||
246 | /** |
||
247 | * Gets an array of database types that map to this Doctrine type. |
||
248 | * |
||
249 | * @param AbstractPlatform $platform |
||
250 | * |
||
251 | * @return string[] |
||
252 | */ |
||
253 | public function getMappedDatabaseTypes(AbstractPlatform $platform): array |
||
261 | } |
||
262 |