1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Numeric; |
4
|
|
|
|
5
|
|
|
// phpcs:disable Generic.Files.LineLength.TooLong |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Types\Type; |
8
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
9
|
|
|
use Doctrine\ORM\Mapping\Builder\FieldBuilder; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\Numeric\IndexedUniqueIntegerFieldInterface; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
12
|
|
|
|
13
|
|
|
// phpcs:enable |
14
|
|
|
|
15
|
|
|
trait IndexedUniqueIntegerFieldTrait |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var int |
19
|
|
|
*/ |
20
|
|
|
private $indexedUniqueInteger; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
24
|
|
|
* @param ClassMetadataBuilder $builder |
25
|
|
|
*/ |
26
|
3 |
|
public static function metaForIndexedUniqueInteger(ClassMetadataBuilder $builder): void |
27
|
|
|
{ |
28
|
3 |
|
$fieldBuilder = new FieldBuilder( |
29
|
3 |
|
$builder, |
30
|
|
|
[ |
31
|
3 |
|
'fieldName' => IndexedUniqueIntegerFieldInterface::PROP_INDEXED_UNIQUE_INTEGER, |
32
|
|
|
'type' => Type::INTEGER, |
33
|
|
|
] |
34
|
|
|
); |
35
|
|
|
$fieldBuilder |
36
|
3 |
|
->columnName( |
37
|
3 |
|
MappingHelper::getColumnNameForField( |
38
|
3 |
|
IndexedUniqueIntegerFieldInterface::PROP_INDEXED_UNIQUE_INTEGER |
39
|
|
|
) |
40
|
|
|
) |
41
|
3 |
|
->nullable(false) |
42
|
3 |
|
->unique(true) |
43
|
3 |
|
->build(); |
44
|
3 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return int |
48
|
|
|
*/ |
49
|
3 |
|
public function getIndexedUniqueInteger(): int |
50
|
|
|
{ |
51
|
3 |
|
return $this->indexedUniqueInteger; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param int indexedUniqueInteger |
56
|
|
|
* |
57
|
|
|
* @return self |
58
|
|
|
*/ |
59
|
3 |
|
private function setIndexedUniqueInteger(int $indexedUniqueInteger): self |
60
|
|
|
{ |
61
|
3 |
|
$this->updatePropertyValue( |
|
|
|
|
62
|
3 |
|
IndexedUniqueIntegerFieldInterface::PROP_INDEXED_UNIQUE_INTEGER, |
63
|
3 |
|
$indexedUniqueInteger |
64
|
|
|
); |
65
|
|
|
|
66
|
3 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
3 |
|
private function initIndexedUniqueInteger() |
70
|
|
|
{ |
71
|
3 |
|
$this->indexedUniqueInteger = IndexedUniqueIntegerFieldInterface::DEFAULT_INDEXED_UNIQUE_INTEGER; |
72
|
3 |
|
} |
73
|
|
|
} |
74
|
|
|
|