1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Entity; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Serializer\Attribute\Groups; |
|
|
|
|
6
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; |
|
|
|
|
7
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
|
|
|
|
8
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
|
|
|
9
|
|
|
use ApiPlatform\Metadata\Get; |
|
|
|
|
10
|
|
|
use ApiPlatform\Metadata\GetCollection; |
|
|
|
|
11
|
|
|
use ApiPlatform\Metadata\Post; |
|
|
|
|
12
|
|
|
use ApiPlatform\Metadata\Put; |
|
|
|
|
13
|
|
|
use ApiPlatform\Metadata\Delete; |
|
|
|
|
14
|
|
|
use ControleOnline\Listener\LogListener; |
|
|
|
|
15
|
|
|
use ControleOnline\Repository\DocumentRepository; |
16
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
|
|
|
17
|
|
|
|
18
|
|
|
|
19
|
|
|
#[ApiResource( |
20
|
|
|
operations: [ |
21
|
|
|
new Get(security: 'is_granted(\'ROLE_CLIENT\')'), |
22
|
|
|
new GetCollection(security: 'is_granted(\'ROLE_CLIENT\')'), |
23
|
|
|
new Put( |
24
|
|
|
security: 'is_granted(\'ROLE_ADMIN\') or (is_granted(\'ROLE_CLIENT\'))', |
25
|
|
|
validationContext: ['groups' => ['document:read']], |
26
|
|
|
denormalizationContext: ['groups' => ['document:write']] |
27
|
|
|
), |
28
|
|
|
new Post(securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')') |
29
|
|
|
], |
30
|
|
|
formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']], |
31
|
|
|
normalizationContext: ['groups' => ['document:read']], |
32
|
|
|
denormalizationContext: ['groups' => ['document:write']] |
33
|
|
|
)] |
34
|
|
|
#[ApiFilter(filterClass: SearchFilter::class, properties: ['people' => 'exact'])] |
35
|
|
|
#[ORM\Table(name: 'document')] |
36
|
|
|
#[ORM\Index(name: 'type_2', columns: ['document_type_id'])] |
37
|
|
|
#[ORM\Index(name: 'file_id', columns: ['file_id'])] |
38
|
|
|
#[ORM\Index(name: 'type', columns: ['people_id', 'document_type_id'])] |
39
|
|
|
#[ORM\UniqueConstraint(name: 'doc', columns: ['document', 'document_type_id'])] |
40
|
|
|
#[ORM\EntityListeners([LogListener::class])] |
41
|
|
|
#[ORM\Entity(repositoryClass: DocumentRepository::class)] |
42
|
|
|
class Document |
43
|
|
|
{ |
44
|
|
|
#[ORM\Column(name: 'id', type: 'integer', nullable: false)] |
45
|
|
|
#[ORM\Id] |
46
|
|
|
#[ORM\GeneratedValue(strategy: 'IDENTITY')] |
47
|
|
|
private int $id = 0; |
48
|
|
|
|
49
|
|
|
#[ORM\Column(name: 'document', type: 'bigint', nullable: false)] |
50
|
|
|
#[Groups(['people:read', 'document:read', 'carrier:read', 'provider:read', 'document:write'])] |
51
|
|
|
private int $document; |
52
|
|
|
|
53
|
|
|
#[ORM\JoinColumn(name: 'people_id', referencedColumnName: 'id', nullable: false)] |
54
|
|
|
#[ORM\ManyToOne(targetEntity: People::class, inversedBy: 'document')] |
55
|
|
|
#[Groups(['document:read', 'document:write'])] |
56
|
|
|
private People $people; |
57
|
|
|
|
58
|
|
|
#[ORM\JoinColumn(name: 'file_id', referencedColumnName: 'id', nullable: true)] |
59
|
|
|
#[ORM\ManyToOne(targetEntity: File::class)] |
60
|
|
|
#[Groups(['document:read', 'document:write'])] |
61
|
|
|
private ?File $file = null; |
|
|
|
|
62
|
|
|
|
63
|
|
|
#[ORM\JoinColumn(name: 'document_type_id', referencedColumnName: 'id', nullable: false)] |
64
|
|
|
#[ORM\ManyToOne(targetEntity: DocumentType::class)] |
65
|
|
|
#[Groups(['people:read', 'document:read', 'carrier:read', 'document:write'])] |
66
|
|
|
private DocumentType $documentType; |
67
|
|
|
|
68
|
|
|
public function getId(): int |
69
|
|
|
{ |
70
|
|
|
return $this->id; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function setDocument(int $document): self |
74
|
|
|
{ |
75
|
|
|
$this->document = $document; |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getDocument(): string |
80
|
|
|
{ |
81
|
|
|
$document = (string) $this->document; |
82
|
|
|
if ($this->getDocumentType()->getDocumentType() === 'CPF') { |
83
|
|
|
return str_pad($document, 11, '0', STR_PAD_LEFT); |
84
|
|
|
} |
85
|
|
|
if ($this->getDocumentType()->getDocumentType() === 'CNPJ') { |
86
|
|
|
return str_pad($document, 14, '0', STR_PAD_LEFT); |
87
|
|
|
} |
88
|
|
|
return $document; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function setFile(?File $file): self |
92
|
|
|
{ |
93
|
|
|
$this->file = $file; |
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getFile(): ?File |
98
|
|
|
{ |
99
|
|
|
return $this->file; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function setPeople(People $people): self |
103
|
|
|
{ |
104
|
|
|
$this->people = $people; |
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getPeople(): People |
109
|
|
|
{ |
110
|
|
|
return $this->people; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function setDocumentType(DocumentType $documentType): self |
114
|
|
|
{ |
115
|
|
|
$this->documentType = $documentType; |
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getDocumentType(): DocumentType |
120
|
|
|
{ |
121
|
|
|
return $this->documentType; |
122
|
|
|
} |
123
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths