1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String; |
4
|
|
|
|
5
|
|
|
// phpcs:disable |
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\String\BusinessIdentifierCodeFieldInterface; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
12
|
|
|
use Symfony\Component\Validator\Constraints\Bic; |
13
|
|
|
use Symfony\Component\Validator\Constraints\Length; |
14
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData; |
15
|
|
|
|
16
|
|
|
// phpcs:enable |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Trait BusinessIdentifierCodeFieldTrait |
20
|
|
|
* |
21
|
|
|
* A Business Identifier Code also known as SWIFT-BIC, BIC, SWIFT ID or SWIFT code |
22
|
|
|
* |
23
|
|
|
* @see https://en.wikipedia.org/wiki/ISO_9362 |
24
|
|
|
* |
25
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String |
26
|
|
|
*/ |
27
|
|
|
trait BusinessIdentifierCodeFieldTrait |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string|null |
32
|
|
|
*/ |
33
|
|
|
private $businessIdentifierCode; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
37
|
|
|
*/ |
38
|
5 |
|
public static function metaForBusinessIdentifierCode(ClassMetadataBuilder $builder): void |
39
|
|
|
{ |
40
|
5 |
|
$fieldBuilder = new FieldBuilder( |
41
|
5 |
|
$builder, |
42
|
|
|
[ |
43
|
5 |
|
'fieldName' => BusinessIdentifierCodeFieldInterface::PROP_BUSINESS_IDENTIFIER_CODE, |
44
|
|
|
'type' => Type::STRING, |
45
|
|
|
'default' => BusinessIdentifierCodeFieldInterface::DEFAULT_BUSINESS_IDENTIFIER_CODE, |
46
|
|
|
] |
47
|
|
|
); |
48
|
|
|
$fieldBuilder |
49
|
5 |
|
->columnName(MappingHelper::getColumnNameForField( |
50
|
5 |
|
BusinessIdentifierCodeFieldInterface::PROP_BUSINESS_IDENTIFIER_CODE |
51
|
|
|
)) |
52
|
5 |
|
->nullable(true) |
53
|
5 |
|
->unique(false) |
54
|
5 |
|
->length(20) |
55
|
5 |
|
->build(); |
56
|
5 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* This method sets the validation for this field. |
60
|
|
|
* |
61
|
|
|
* You should add in as many relevant property constraints as you see fit. |
62
|
|
|
* |
63
|
|
|
* @see https://symfony.com/doc/current/validation.html#supported-constraints |
64
|
|
|
* |
65
|
|
|
* @param ValidatorClassMetaData $metadata |
66
|
|
|
* |
67
|
|
|
* @throws \Symfony\Component\Validator\Exception\MissingOptionsException |
68
|
|
|
* @throws \Symfony\Component\Validator\Exception\InvalidOptionsException |
69
|
|
|
* @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
70
|
|
|
*/ |
71
|
5 |
|
protected static function validatorMetaForPropertyBusinessIdentifierCode(ValidatorClassMetaData $metadata): void |
72
|
|
|
{ |
73
|
5 |
|
$metadata->addPropertyConstraints( |
74
|
5 |
|
BusinessIdentifierCodeFieldInterface::PROP_BUSINESS_IDENTIFIER_CODE, |
75
|
|
|
[ |
76
|
5 |
|
new Bic(), |
77
|
5 |
|
new Length( |
78
|
|
|
[ |
79
|
5 |
|
'min' => 0, |
80
|
|
|
'max' => 20, |
81
|
|
|
] |
82
|
|
|
), |
83
|
|
|
] |
84
|
|
|
); |
85
|
5 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string|null |
89
|
|
|
*/ |
90
|
5 |
|
public function getBusinessIdentifierCode(): ?string |
91
|
|
|
{ |
92
|
5 |
|
if (null === $this->businessIdentifierCode) { |
93
|
5 |
|
return BusinessIdentifierCodeFieldInterface::DEFAULT_BUSINESS_IDENTIFIER_CODE; |
94
|
|
|
} |
95
|
|
|
|
96
|
5 |
|
return $this->businessIdentifierCode; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string|null $businessIdentifierCode |
101
|
|
|
* |
102
|
|
|
* @return self |
103
|
|
|
*/ |
104
|
5 |
|
private function setBusinessIdentifierCode(?string $businessIdentifierCode): self |
105
|
|
|
{ |
106
|
5 |
|
$this->updatePropertyValue( |
|
|
|
|
107
|
5 |
|
BusinessIdentifierCodeFieldInterface::PROP_BUSINESS_IDENTIFIER_CODE, |
108
|
5 |
|
$businessIdentifierCode |
109
|
|
|
); |
110
|
|
|
|
111
|
5 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|