|
1
|
|
|
<?php |
|
2
|
|
|
namespace Isign\Document; |
|
3
|
|
|
|
|
4
|
|
|
use Isign\DocumentTypeProvider; |
|
5
|
|
|
use Isign\FileFieldsTrait; |
|
6
|
|
|
use Isign\QueryInterface; |
|
7
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Seal a signed document. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Seal implements QueryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use FileFieldsTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string document type */ |
|
17
|
|
|
private $type; |
|
18
|
|
|
|
|
19
|
|
|
/** @var boolean add document timestamp */ |
|
20
|
|
|
private $timestamp; |
|
21
|
|
|
|
|
22
|
|
|
/** @var array document to be signed */ |
|
23
|
|
|
private $document; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $type string document type |
|
27
|
|
|
* @param array $document document to be signed |
|
28
|
|
|
* @param boolean $timestamp boolean add document timestamp |
|
29
|
|
|
*/ |
|
30
|
7 |
|
public function __construct( |
|
31
|
|
|
$type, |
|
32
|
|
|
array $document, |
|
33
|
|
|
$timestamp |
|
34
|
|
|
) { |
|
35
|
7 |
|
$this->type = $type; |
|
36
|
7 |
|
$this->timestamp = $timestamp; |
|
37
|
7 |
|
$this->document = $document; |
|
38
|
7 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get fields |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
3 |
|
public function getFields() |
|
45
|
|
|
{ |
|
46
|
3 |
|
$params = $this->document; |
|
47
|
|
|
|
|
48
|
3 |
|
if (isset($params['files'])) { |
|
49
|
3 |
|
$params['files'] = $this->getMultipleFileFields($params['files']); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$return = [ |
|
53
|
2 |
|
'type' => $this->type, |
|
54
|
2 |
|
$this->type => $params |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
2 |
|
if ($this->timestamp !== null) { |
|
58
|
2 |
|
$return['timestamp'] = $this->timestamp; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
return $return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Validation constraints for request data validation |
|
66
|
|
|
* @return Assert\Collection |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function getValidationConstraints() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return new Assert\Collection([ |
|
71
|
1 |
|
'type' => new Assert\Required([ |
|
72
|
1 |
|
new Assert\NotBlank(), |
|
73
|
1 |
|
new Assert\Choice([ |
|
74
|
1 |
|
'choices' => DocumentTypeProvider::getAllDocumentTypes() |
|
75
|
|
|
]) |
|
76
|
|
|
]), |
|
77
|
1 |
|
'timestamp' => new Assert\Required([ |
|
78
|
1 |
|
new Assert\Type([ |
|
79
|
1 |
|
'type' => 'bool' |
|
80
|
|
|
]) |
|
81
|
|
|
]), |
|
82
|
1 |
|
$this->type => new Assert\Collection([]), |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Result object for this query result |
|
88
|
|
|
* @return SealResult |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function createResult() |
|
91
|
|
|
{ |
|
92
|
1 |
|
return new SealResult(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* API action name, part of full url |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function getAction() |
|
100
|
|
|
{ |
|
101
|
1 |
|
return 'seal'; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* HTTP method to use |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function getMethod() |
|
109
|
|
|
{ |
|
110
|
1 |
|
return QueryInterface::POST; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|