|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* tubee.io |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copryright (c) 2017-2019 gyselroth GmbH (https://gyselroth.com) |
|
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Tubee\Rest\v1; |
|
13
|
|
|
|
|
14
|
|
|
use Fig\Http\Message\StatusCodeInterface; |
|
15
|
|
|
use Lcobucci\ContentNegotiation\UnformattedResponse; |
|
16
|
|
|
use Micro\Auth\Identity; |
|
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
18
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
19
|
|
|
use Rs\Json\Patch; |
|
20
|
|
|
use Tubee\Acl; |
|
21
|
|
|
use Tubee\ResourceNamespace\Factory as ResourceNamespaceFactory; |
|
22
|
|
|
use Tubee\Rest\Helper; |
|
23
|
|
|
use Tubee\Workflow\Factory as WorkflowFactory; |
|
24
|
|
|
use Zend\Diactoros\Response; |
|
25
|
|
|
|
|
26
|
|
|
class Workflows |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* ResourceNamespace factory. |
|
30
|
|
|
* |
|
31
|
|
|
* @var ResourceNamespaceFactory |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $namespace_factory; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Workflow factory. |
|
37
|
|
|
* |
|
38
|
|
|
* @var WorkflowFactory |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $workflow_factory; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Acl. |
|
44
|
|
|
* |
|
45
|
|
|
* @var Acl |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $acl; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Init. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(ResourceNamespaceFactory $namespace_factory, WorkflowFactory $workflow_factory, Acl $acl) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->namespace_factory = $namespace_factory; |
|
55
|
|
|
$this->workflow_factory = $workflow_factory; |
|
56
|
|
|
$this->acl = $acl; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Entrypoint. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getAll(ServerRequestInterface $request, Identity $identity, string $namespace, string $collection, string $endpoint): ResponseInterface |
|
63
|
|
|
{ |
|
64
|
|
|
$query = array_merge([ |
|
65
|
|
|
'offset' => 0, |
|
66
|
|
|
'limit' => 20, |
|
67
|
|
|
], $request->getQueryParams()); |
|
68
|
|
|
|
|
69
|
|
|
$namespace = $this->namespace_factory->getOne($namespace); |
|
70
|
|
|
$endpoint = $namespace->getCollection($collection)->getEndpoint($endpoint); |
|
71
|
|
|
|
|
72
|
|
|
if (isset($query['watch'])) { |
|
73
|
|
|
$cursor = $this->workflow_factory->watch($endpoint, null, true, $query['query'], (int) $query['offset'], (int) $query['limit'], $query['sort']); |
|
74
|
|
|
|
|
75
|
|
|
return Helper::watchAll($request, $identity, $this->acl, $cursor); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$workflows = $endpoint->getWorkflows($query['query'], (int) $query['offset'], (int) $query['limit'], $query['sort']); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
return Helper::getAll($request, $identity, $this->acl, $workflows); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Entrypoint. |
|
85
|
|
|
*/ |
|
86
|
|
View Code Duplication |
public function getOne(ServerRequestInterface $request, Identity $identity, string $namespace, string $collection, string $endpoint, string $workflow): ResponseInterface |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
$namespace = $this->namespace_factory->getOne($namespace); |
|
89
|
|
|
$workflow = $namespace->getCollection($collection)->getEndpoint($endpoint)->getWorkflow($workflow); |
|
90
|
|
|
|
|
91
|
|
|
return Helper::getOne($request, $identity, $workflow); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Create. |
|
96
|
|
|
*/ |
|
97
|
|
View Code Duplication |
public function post(ServerRequestInterface $request, Identity $identity, string $namespace, string $collection, string $endpoint): ResponseInterface |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
$body = $request->getParsedBody(); |
|
100
|
|
|
$query = $request->getQueryParams(); |
|
101
|
|
|
|
|
102
|
|
|
$namespace = $this->namespace_factory->getOne($namespace); |
|
103
|
|
|
$endpoint = $namespace->getCollection($collection)->getEndpoint($endpoint); |
|
104
|
|
|
$this->workflow_factory->add($endpoint, $body); |
|
105
|
|
|
|
|
106
|
|
|
return new UnformattedResponse( |
|
107
|
|
|
(new Response())->withStatus(StatusCodeInterface::STATUS_CREATED), |
|
108
|
|
|
$endpoint->getWorkflow($body['name'])->decorate($request), |
|
109
|
|
|
['pretty' => isset($query['pretty'])] |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Delete. |
|
115
|
|
|
*/ |
|
116
|
|
|
public function delete(ServerRequestInterface $request, Identity $identity, string $namespace, string $collection, string $endpoint, string $workflow): ResponseInterface |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
$namespace = $this->namespace_factory->getOne($namespace); |
|
119
|
|
|
$endpoint = $namespace->getCollection($collection)->getEndpoint($endpoint); |
|
120
|
|
|
$this->workflow_factory->deleteOne($endpoint, $workflow); |
|
121
|
|
|
|
|
122
|
|
|
return(new Response())->withStatus(StatusCodeInterface::STATUS_NO_CONTENT); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Patch. |
|
127
|
|
|
*/ |
|
128
|
|
View Code Duplication |
public function patch(ServerRequestInterface $request, Identity $identity, string $namespace, string $collection, string $endpoint, string $workflow): ResponseInterface |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
$body = $request->getParsedBody(); |
|
131
|
|
|
$query = $request->getQueryParams(); |
|
132
|
|
|
$namespace = $this->namespace_factory->getOne($namespace); |
|
133
|
|
|
$endpoint = $namespace->getCollection($collection)->getEndpoint($endpoint); |
|
134
|
|
|
$workflow = $endpoint->getWorkflow($workflow); |
|
135
|
|
|
$doc = ['data' => $workflow->getData()]; |
|
136
|
|
|
|
|
137
|
|
|
$patch = new Patch(json_encode($doc), json_encode($body)); |
|
138
|
|
|
$patched = $patch->apply(); |
|
139
|
|
|
$update = json_decode($patched, true); |
|
140
|
|
|
|
|
141
|
|
|
$this->workflow_factory->update($workflow, $update); |
|
142
|
|
|
|
|
143
|
|
|
return new UnformattedResponse( |
|
144
|
|
|
(new Response())->withStatus(StatusCodeInterface::STATUS_OK), |
|
145
|
|
|
$endpoint->getWorkflow($workflow->getName())->decorate($request), |
|
146
|
|
|
['pretty' => isset($query['pretty'])] |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.