1
|
|
|
<?php declare (strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Data\Migrations; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2019 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
22
|
|
|
use Doctrine\DBAL\Types\Type; |
23
|
|
|
use function array_key_exists; |
24
|
|
|
use function array_map; |
25
|
|
|
use function assert; |
26
|
|
|
use function implode; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @package Limoncello\Data |
30
|
|
|
*/ |
31
|
|
|
class EnumType extends Type |
32
|
|
|
{ |
33
|
|
|
/** Type name */ |
34
|
|
|
const TYPE_NAME = 'EnumValues'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
*/ |
39
|
2 |
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
40
|
|
|
{ |
41
|
2 |
|
assert( |
42
|
2 |
|
array_key_exists(static::TYPE_NAME, $fieldDeclaration), |
43
|
2 |
|
'Enum values are not set. Use `Column::setCustomSchemaOption` to set them.' |
44
|
|
|
); |
45
|
2 |
|
$values = $fieldDeclaration[static::TYPE_NAME]; |
46
|
|
|
|
47
|
|
|
$quotedValues = array_map(function (string $value) use ($platform, $values) : string { |
48
|
2 |
|
return $platform->quoteStringLiteral($value); |
49
|
2 |
|
}, $values); |
50
|
|
|
|
51
|
2 |
|
$valueList = implode(',', $quotedValues); |
52
|
|
|
|
53
|
2 |
|
return "ENUM($valueList)"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
1 |
|
public function getName() |
60
|
|
|
{ |
61
|
1 |
|
return self::TYPE_NAME; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|