|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
6
|
|
|
use App\Library\Provider\Signature\SignatureFactory; |
|
|
|
|
|
|
7
|
|
|
use App\Library\Provider\Signature\Contract as SignatureContract; |
|
|
|
|
|
|
8
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
|
|
9
|
|
|
use ControleOnline\Entity\Config; |
|
|
|
|
|
|
10
|
|
|
use ControleOnline\Entity\Contract; |
|
11
|
|
|
use ControleOnline\Entity\File; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class SignatureService |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
public function __construct( |
|
17
|
|
|
private EntityManagerInterface $manager, |
|
18
|
|
|
private PeopleRoleService $peopleRoleService, |
|
|
|
|
|
|
19
|
|
|
private SignatureContract $signatureContract, |
|
20
|
|
|
private PdfService $pdf, |
|
|
|
|
|
|
21
|
|
|
private ModelService $modelService |
|
|
|
|
|
|
22
|
|
|
) {} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
public function sign(Contract $data) |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->signatureContract->sign($data); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function genetateFromModel(Contract $data) |
|
31
|
|
|
{ |
|
32
|
|
|
$file = $data->getContractFile(); |
|
33
|
|
|
if (!$file) |
|
34
|
|
|
$file = new File(); |
|
35
|
|
|
|
|
36
|
|
|
$file->setFileType('text'); |
|
37
|
|
|
$file->setExtension('html'); |
|
38
|
|
|
$file->setContent($this->modelService->genetateFromModel($data)); |
|
39
|
|
|
$this->manager->persist($file); |
|
40
|
|
|
$this->manager->flush(); |
|
41
|
|
|
|
|
42
|
|
|
return $data; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function getContractPDFContent(Contract $contract): string |
|
47
|
|
|
{ |
|
48
|
|
|
$content = $contract->getContractFile()->getContent(); |
|
49
|
|
|
|
|
50
|
|
|
if ($contract->getContractFile()->getExtension() == 'pdf') |
|
51
|
|
|
return $content; |
|
52
|
|
|
|
|
53
|
|
|
if (empty($content)) { |
|
54
|
|
|
throw new \Exception( |
|
55
|
|
|
sprintf('Houve um erro ao gerar o PDF') |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $this->pdf->convertHtmlToPdf($content); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getFactory(?string $factoryName = null): ?SignatureFactory |
|
63
|
|
|
{ |
|
64
|
|
|
$providerName = $factoryName === null ? |
|
65
|
|
|
$this->getDefaultProviderFromConfig() : $factoryName; |
|
66
|
|
|
|
|
67
|
|
|
if ($providerName === null) { |
|
68
|
|
|
return null; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$provider = sprintf( |
|
72
|
|
|
'\\App\\Library\\Provider\\Signature\\%s\\Factory', |
|
73
|
|
|
ucfirst(strtolower($providerName)) |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
if (!class_exists($provider)) { |
|
77
|
|
|
throw new \Exception('Signature provider factory not found'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return new $provider( |
|
81
|
|
|
$this->getProviderConfig($providerName) |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
private function getProviderConfig(string $providerName): ?array |
|
87
|
|
|
{ |
|
88
|
|
|
|
|
89
|
|
|
$myCompany = $this->peopleRoleService->getMainCompany(); |
|
90
|
|
|
if ($myCompany instanceof People) { |
|
91
|
|
|
|
|
92
|
|
|
return $this->manager->getRepository(Config::class) |
|
93
|
|
|
->getKeyValuesByPeople( |
|
94
|
|
|
$myCompany, |
|
95
|
|
|
strtolower($providerName) |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
throw new \Exception('Company not found'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
private function getDefaultProviderFromConfig(): ?string |
|
103
|
|
|
{ |
|
104
|
|
|
$myCompany = $this->peopleRoleService->getMainCompany(); |
|
105
|
|
|
if ($myCompany instanceof People) { |
|
106
|
|
|
$configs = $this->manager->getRepository(Config::class) |
|
107
|
|
|
->getKeyValuesByPeople( |
|
108
|
|
|
$myCompany, |
|
109
|
|
|
'provider' |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
if ($configs === null) { |
|
113
|
|
|
return null; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return isset($configs['provider-signature']) ? |
|
117
|
|
|
$configs['provider-signature'] : null; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
throw new \Exception('Company not found'); |
|
121
|
|
|
} |
|
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