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