|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gewebe\SyliusVATPlugin\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use DateTime; |
|
8
|
|
|
use Doctrine\DBAL\Types\Types; |
|
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
10
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
11
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
12
|
|
|
use TestApplication\src\Entity\Addressing\Address; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait that implements the vat number functionality |
|
16
|
|
|
* Used in: |
|
17
|
|
|
* <li>@see Address</li> |
|
18
|
|
|
*/ |
|
19
|
|
|
trait VatNumberAwareTrait |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @ORM\Column(name="vat_number", type="string", nullable=true) |
|
23
|
|
|
* |
|
24
|
|
|
* @Gedmo\Versioned() |
|
25
|
|
|
* |
|
26
|
|
|
* @Groups({"shop:address:read", "shop:address:create", "shop:address:update"}) |
|
27
|
|
|
*/ |
|
28
|
|
|
#[ORM\Column(name: 'vat_number', type: Types::STRING, nullable: true)] |
|
29
|
|
|
#[Gedmo\Versioned()] |
|
30
|
|
|
#[Groups(['shop:address:read', 'shop:address:create', 'shop:address:update'])] |
|
31
|
|
|
protected ?string $vatNumber = null; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @ORM\Column(name="vat_valid", type="boolean") |
|
35
|
|
|
* |
|
36
|
|
|
* @Groups({"shop:address:read"}) |
|
37
|
|
|
*/ |
|
38
|
|
|
#[ORM\Column(name: 'vat_valid', type: Types::BOOLEAN)] |
|
39
|
|
|
#[Groups(['shop:address:read'])] |
|
40
|
|
|
protected bool $vatValid = false; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @ORM\Column(name="vat_validated_at", type="datetime", nullable=true) |
|
44
|
|
|
* |
|
45
|
|
|
* @Groups({"shop:address:read"}) |
|
46
|
|
|
*/ |
|
47
|
|
|
#[ORM\Column(name: 'vat_validated_at', type: Types::DATETIME_MUTABLE, nullable: true)] |
|
48
|
|
|
#[Groups(['shop:address:read'])] |
|
49
|
|
|
protected ?DateTime $vatValidatedAt = null; |
|
50
|
|
|
|
|
51
|
|
|
public function getVatNumber(): ?string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->vatNumber; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setVatNumber(?string $vatNumber): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->vatNumber = $vatNumber; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function hasVatNumber(): bool |
|
62
|
|
|
{ |
|
63
|
|
|
return is_string($this->vatNumber) && strlen($this->vatNumber) > 0; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function hasValidVatNumber(): bool |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->hasVatNumber() && $this->vatValid === true; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function setVatValid(bool $valid, ?DateTime $validatedAt = null): void |
|
72
|
|
|
{ |
|
73
|
|
|
$this->vatValid = $valid; |
|
74
|
|
|
$this->vatValidatedAt = $validatedAt ?? new DateTime(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getVatValidatedAt(): ?DateTime |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->vatValidatedAt; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: