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\ArchiveResult; |
7
|
|
|
use Dokobit\Gateway\Result\ResultInterface; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Archive a signed file. |
12
|
|
|
* @see https://gateway-sandbox.dokobit.com/api/doc#_api_archive |
13
|
|
|
*/ |
14
|
|
|
class Archive 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, or a token of an already uploaded file */ |
22
|
|
|
private $path; |
23
|
|
|
|
24
|
|
|
/** @var bool if true: $path will be treated as token, if false: $path is a path to file */ |
25
|
|
|
private $pathIsToken; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $type intended type of the signed file |
29
|
|
|
* @param string $path path of the file to be uploded, or a token of an already uploaded file |
30
|
|
|
* @param bool $pathIsToken if true, $path if is an uploaded file token, not a path (defaults to false) |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
string $type, |
34
|
|
|
string $path, |
35
|
|
|
bool $pathIsToken = false |
36
|
|
|
) { |
37
|
|
|
$this->type = $type; |
38
|
|
|
$this->path = $path; |
39
|
|
|
$this->pathIsToken = $pathIsToken; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Field and values association used in query |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function getFields(): array |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
'type' => $this->type, |
50
|
|
|
'file' => $this->pathIsToken ? |
51
|
|
|
[ 'token' => $this->path ] : |
52
|
|
|
$this->getFileFields($this->path), |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Validation constraints for request data validation |
58
|
|
|
* @return Assert\Collection |
59
|
|
|
*/ |
60
|
|
|
public function getValidationConstraints(): Assert\Collection |
61
|
|
|
{ |
62
|
|
|
return new Assert\Collection([ |
63
|
|
|
'type' => new Assert\Required([ |
64
|
|
|
new Assert\NotBlank(), |
65
|
|
|
new Assert\Choice([ |
66
|
|
|
'choices' => DocumentTypeProvider::getPrimaryDocumentTypes(), |
67
|
|
|
]), |
68
|
|
|
]), |
69
|
|
|
'file' => new Assert\Required([ |
70
|
|
|
new Assert\NotBlank(), |
71
|
|
|
new Assert\Collection([ |
72
|
|
|
'token' => new Assert\Optional([ |
73
|
|
|
new Assert\NotBlank(), |
74
|
|
|
]), |
75
|
|
|
'name' => new Assert\Optional([ |
76
|
|
|
new Assert\NotBlank(), |
77
|
|
|
]), |
78
|
|
|
'content' => new Assert\Optional([ |
79
|
|
|
new Assert\NotBlank(), |
80
|
|
|
]), |
81
|
|
|
'digest' => new Assert\Optional([ |
82
|
|
|
new Assert\NotBlank(), |
83
|
|
|
]), |
84
|
|
|
]), |
85
|
|
|
]), |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Result object for this query result |
91
|
|
|
* @return ArchiveResult |
92
|
|
|
*/ |
93
|
|
|
public function createResult(): ResultInterface |
94
|
|
|
{ |
95
|
|
|
return new ArchiveResult(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* API action name, part of full API request url |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getAction(): string |
103
|
|
|
{ |
104
|
|
|
return 'archive'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* HTTP method to use |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getMethod(): string |
112
|
|
|
{ |
113
|
|
|
return QueryInterface::POST; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|