Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit a56ad7d

Browse files
committed
Merge branch 'develop'
* develop: Code cleanup: Remove unused import New functionality: CamundaProcessInstanceService::getList() and ::delete(). Move CamundaRestRequest::responseToJson() to CamundaResponse::restResponseToJson().
2 parents 3c6f39d + 9cc3fa0 commit a56ad7d

10 files changed

+493
-20
lines changed

src/CamundaProcessInstance.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace StrehleDe\CamundaClient;
4+
5+
6+
class CamundaProcessInstance
7+
{
8+
protected string $businessKey;
9+
protected string $caseInstanceId;
10+
protected string $definitionId;
11+
protected bool $ended;
12+
protected string $id;
13+
protected bool $suspended;
14+
protected string $tenantId;
15+
16+
17+
/**
18+
* @param array $json
19+
* @return self
20+
*/
21+
public function fromJson(array $json): self
22+
{
23+
$propertyValues = CamundaUtils::jsonToPropertyValues(
24+
$json,
25+
get_class($this),
26+
$this->getPropertiesToCopyFromRestResponse()
27+
);
28+
29+
foreach ($propertyValues as $propertyName => $value) {
30+
$this->{$propertyName} = $value;
31+
}
32+
33+
return $this;
34+
}
35+
36+
37+
/**
38+
* @return array
39+
*/
40+
protected function getPropertiesToCopyFromRestResponse(): array
41+
{
42+
return [
43+
'businessKey',
44+
'caseInstanceId',
45+
'definitionId',
46+
'ended',
47+
'id',
48+
'suspended',
49+
'tenantId'
50+
];
51+
}
52+
53+
54+
/**
55+
* @return string|null
56+
*/
57+
public function getBusinessKey(): ?string
58+
{
59+
return $this->businessKey ?? null;
60+
}
61+
62+
63+
/**
64+
* @return string|null
65+
*/
66+
public function getCaseInstanceId(): ?string
67+
{
68+
return $this->caseInstanceId ?? null;
69+
}
70+
71+
72+
/**
73+
* @return string|null
74+
*/
75+
public function getDefinitionId(): ?string
76+
{
77+
return $this->definitionId ?? null;
78+
}
79+
80+
81+
/**
82+
* @return bool|null
83+
*/
84+
public function isEnded(): ?bool
85+
{
86+
return $this->ended ?? null;
87+
}
88+
89+
90+
/**
91+
* @return string|null
92+
*/
93+
public function getId(): ?string
94+
{
95+
return $this->id ?? null;
96+
}
97+
98+
99+
/**
100+
* @return bool|null
101+
*/
102+
public function isSuspended(): ?bool
103+
{
104+
return $this->suspended ?? null;
105+
}
106+
107+
108+
/**
109+
* @return string|null
110+
*/
111+
public function getTenantId(): ?string
112+
{
113+
return $this->tenantId ?? null;
114+
}
115+
}

src/CamundaProcessInstanceBag.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace StrehleDe\CamundaClient;
4+
5+
use ArrayIterator;
6+
7+
8+
/**
9+
* Class CamundaProcessInstanceBag
10+
* @package StrehleDe\CamundaClient
11+
*/
12+
class CamundaProcessInstanceBag extends ArrayIterator
13+
{
14+
public function __construct(CamundaProcessInstance ...$instances)
15+
{
16+
parent::__construct($instances);
17+
}
18+
19+
20+
public function current(): CamundaProcessInstance
21+
{
22+
return parent::current();
23+
}
24+
25+
26+
public function offsetGet($offset): CamundaProcessInstance
27+
{
28+
return parent::offsetGet($offset);
29+
}
30+
}

src/CamundaResponse.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace StrehleDe\CamundaClient;
44

55

6+
use Psr\Http\Message\ResponseInterface;
7+
68
abstract class CamundaResponse
79
{
810
/**
@@ -32,4 +34,20 @@ protected function getPropertiesToCopyFromJson(): array
3234
{
3335
return [];
3436
}
37+
38+
39+
/**
40+
* Parse JSON response string into array, throw exception on error response
41+
*
42+
* @param ResponseInterface $response
43+
* @return array
44+
*/
45+
public static function restResponseToJson(ResponseInterface $response): array
46+
{
47+
if (!in_array('application/json', $response->getHeader('Content-Type'))) {
48+
return [];
49+
}
50+
51+
return json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
52+
}
3553
}

src/CamundaRestRequest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,4 @@ public function send(): ResponseInterface
146146
throw new CamundaRequestException($restResponse->message ?? json_encode($restResponse));
147147
*/
148148
}
149-
150-
151-
/**
152-
* Parse JSON response string into array, throw exception on error response
153-
*
154-
* @param ResponseInterface $response
155-
* @return array
156-
*/
157-
public static function responseToJson(ResponseInterface $response): array
158-
{
159-
if (!in_array('application/json', $response->getHeader('Content-Type'))) {
160-
return [];
161-
}
162-
163-
return json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
164-
}
165149
}

src/Service/ExternalTask/CamundaExternalTaskFetchAndLockResponse.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use StrehleDe\CamundaClient\CamundaExternalTask;
77
use StrehleDe\CamundaClient\CamundaExternalTaskBag;
88
use StrehleDe\CamundaClient\CamundaResponse;
9-
use StrehleDe\CamundaClient\CamundaRestRequest;
109
use StrehleDe\CamundaClient\Exception\CamundaRequestException;
1110

1211

@@ -35,7 +34,7 @@ public function __construct()
3534
*/
3635
public function fromRestResponse(ResponseInterface $restResponse): self
3736
{
38-
$json = CamundaRestRequest::responseToJson($restResponse);
37+
$json = CamundaResponse::restResponseToJson($restResponse);
3938

4039
if (!is_array($json)) {
4140
throw new CamundaRequestException(sprintf('%s: Response is not an array', __METHOD__));

src/Service/ProcessDefinition/CamundaProcessDefinitionStartInstanceResponse.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Psr\Http\Message\ResponseInterface;
66
use StrehleDe\CamundaClient\CamundaResponse;
7-
use StrehleDe\CamundaClient\CamundaRestRequest;
87
use StrehleDe\CamundaClient\Variable\CamundaVariableBag;
98

109

@@ -40,7 +39,7 @@ public function __construct()
4039
*/
4140
public function fromRestResponse(ResponseInterface $restResponse): self
4241
{
43-
$json = CamundaRestRequest::responseToJson($restResponse);
42+
$json = CamundaResponse::restResponseToJson($restResponse);
4443

4544
parent::jsonToProperties($json);
4645

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace StrehleDe\CamundaClient\Service\ProcessInstance;
4+
5+
use GuzzleHttp\RequestOptions;
6+
use StrehleDe\CamundaClient\CamundaRequest;
7+
use StrehleDe\CamundaClient\CamundaRestRequest;
8+
9+
10+
class CamundaProcessInstanceDeleteRequest extends CamundaRequest
11+
{
12+
protected bool $failIfNotExists;
13+
protected string $id;
14+
15+
16+
/**
17+
* @return CamundaRestRequest
18+
*/
19+
public function toRestRequest(): CamundaRestRequest
20+
{
21+
$query = [];
22+
23+
if ($this->isFailIfNotExists() !== null) {
24+
$query['failIfNotExists'] = $this->isFailIfNotExists();
25+
}
26+
27+
return (new CamundaRestRequest($this->camundaClient))
28+
->setRequestUrl('/process-instance/' . urlencode($this->getId()))
29+
->setRequestMethod('DELETE')
30+
->setRequestOption(RequestOptions::QUERY, $query);
31+
}
32+
33+
34+
/**
35+
* @return string[]
36+
*/
37+
protected function getRequiredProperties(): array
38+
{
39+
return ['id'];
40+
}
41+
42+
43+
/**
44+
* @return string|null
45+
*/
46+
public function getId(): ?string
47+
{
48+
return $this->id ?? null;
49+
}
50+
51+
52+
/**
53+
* @param string $id
54+
* @return self
55+
*/
56+
public function setId(string $id): self
57+
{
58+
$this->id = $id;
59+
return $this;
60+
}
61+
62+
63+
/**
64+
* @return bool|null
65+
*/
66+
public function isFailIfNotExists(): ?bool
67+
{
68+
return $this->failIfNotExists ?? null;
69+
}
70+
71+
72+
/**
73+
* @param bool $failIfNotExists
74+
* @return self
75+
*/
76+
public function setFailIfNotExists(bool $failIfNotExists): self
77+
{
78+
$this->failIfNotExists = $failIfNotExists;
79+
return $this;
80+
}
81+
}

0 commit comments

Comments
 (0)