1
|
|
|
<?php |
2
|
|
|
namespace Dokobit\Gateway\Query\File; |
3
|
|
|
|
4
|
|
|
use Dokobit\Gateway\DocumentTypeProvider; |
5
|
|
|
use Dokobit\Gateway\Query\QueryInterface; |
6
|
|
|
use Dokobit\Gateway\Result\File\CheckResult; |
7
|
|
|
use Dokobit\Gateway\Result\ResultInterface; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Check validity of a signed file. |
12
|
|
|
* @see https://gateway-sandbox.dokobit.com/api/doc#_api_file_check |
13
|
|
|
*/ |
14
|
|
|
class Check implements QueryInterface |
15
|
|
|
{ |
16
|
|
|
use FileFieldsTrait; |
17
|
|
|
|
18
|
|
|
/** @var string intended type of the archived document */ |
19
|
|
|
private $type; |
20
|
|
|
|
21
|
|
|
/** @var string path of the file to be uploded */ |
22
|
|
|
private $path; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param string $type intended type of the signed file |
26
|
|
|
* @param string $path path of the file to be uploded |
27
|
|
|
*/ |
28
|
|
|
public function __construct( |
29
|
|
|
string $type, |
30
|
|
|
string $path |
31
|
|
|
) { |
32
|
|
|
$this->type = $type; |
33
|
|
|
$this->path = $path; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Field and values association used in query |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function getFields(): array |
41
|
|
|
{ |
42
|
|
|
return [ |
43
|
|
|
'type' => $this->type, |
44
|
|
|
'file' => $this->getFileFields($this->path), |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Validation constraints for request data validation |
50
|
|
|
* @return Assert\Collection |
51
|
|
|
*/ |
52
|
|
|
public function getValidationConstraints(): Assert\Collection |
53
|
|
|
{ |
54
|
|
|
return new Assert\Collection([ |
55
|
|
|
'type' => new Assert\Required([ |
56
|
|
|
new Assert\NotBlank(), |
57
|
|
|
new Assert\Choice([ |
58
|
|
|
'choices' => DocumentTypeProvider::getPrimaryDocumentTypes(), |
59
|
|
|
]), |
60
|
|
|
]), |
61
|
|
|
'file' => new Assert\Required([ |
62
|
|
|
new Assert\NotBlank(), |
63
|
|
|
new Assert\Collection([ |
64
|
|
|
'name' => new Assert\Required([ |
65
|
|
|
new Assert\NotBlank(), |
66
|
|
|
]), |
67
|
|
|
'content' => new Assert\Required([ |
68
|
|
|
new Assert\NotBlank(), |
69
|
|
|
]), |
70
|
|
|
'digest' => new Assert\Required([ |
71
|
|
|
new Assert\NotBlank(), |
72
|
|
|
]), |
73
|
|
|
]), |
74
|
|
|
]), |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Result object for this query result |
80
|
|
|
* @return CheckResult |
81
|
|
|
*/ |
82
|
|
|
public function createResult(): ResultInterface |
83
|
|
|
{ |
84
|
|
|
return new CheckResult(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* API action name, part of full API request url |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getAction(): string |
92
|
|
|
{ |
93
|
|
|
return 'file/check'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* HTTP method to use |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getMethod(): string |
101
|
|
|
{ |
102
|
|
|
return QueryInterface::POST; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|