Skip to content

Commit 18f2ab9

Browse files
authored
Support netresearch/jsonmapper ^5.0 (#551)
* Support netresearch/jsonmapper ^5.0 * codefactor fix
1 parent 0289d77 commit 18f2ab9

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
"php": "^8.0",
88
"ext-curl": "*",
99
"ext-json": "*",
10-
"netresearch/jsonmapper": "^4.2",
11-
"monolog/monolog": "^2.0|^3.0"
12-
},
13-
"suggest": {
10+
"netresearch/jsonmapper": "^4.2|^5.0",
11+
"monolog/monolog": "^2.0|^3.0",
1412
"vlucas/phpdotenv": "^5.0|^6.0"
1513
},
1614
"require-dev": {

src/JiraClient.php

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public function __construct(?ConfigurationInterface $configuration = null, ?Logg
7373

7474
$this->json_mapper = new \JsonMapper();
7575

76+
// Adjust settings for JsonMapper v5.0 BC
77+
if (property_exists($this->json_mapper, 'bStrictNullTypesInArrays')) {
78+
$this->json_mapper->bStrictNullTypesInArrays = false; // if you want to allow nulls in arrays
79+
}
80+
$this->json_mapper->bStrictNullTypes = false; // if you want to allow nulls
81+
$this->json_mapper->bStrictObjectTypeChecking = false; // if you want to disable strict type checking
82+
7683
// Fix "\JiraRestApi\JsonMapperHelper::class" syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
7784
$this->json_mapper->undefinedPropertyHandler = [new \JiraRestApi\JsonMapperHelper(), 'setUndefinedProperty'];
7885

@@ -198,31 +205,7 @@ public function exec(string $context, array|string|null $post_data = null, ?stri
198205
$this->log->info("Curl $custom_request: $url JsonData=".json_encode($post_data, JSON_UNESCAPED_UNICODE));
199206
}
200207

201-
curl_reset($this->curl);
202-
$ch = $this->curl;
203-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->configuration->getTimeout());
204-
curl_setopt($ch, CURLOPT_TIMEOUT, $this->configuration->getTimeout());
205-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
206-
curl_setopt($ch, CURLOPT_URL, $url);
207-
208-
// post_data
209-
if (!is_null($post_data)) {
210-
// PUT REQUEST
211-
if (!is_null($custom_request) && $custom_request == 'PUT') {
212-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
213-
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
214-
}
215-
if (!is_null($custom_request) && $custom_request == 'DELETE') {
216-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
217-
} else {
218-
curl_setopt($ch, CURLOPT_POST, true);
219-
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
220-
}
221-
} else {
222-
if (!is_null($custom_request) && $custom_request == 'DELETE') {
223-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
224-
}
225-
}
208+
$ch = $this->prepareCurlRequest($url, $post_data, $custom_request);
226209

227210
// save HTTP Headers
228211
$curl_http_headers = [
@@ -621,6 +604,37 @@ private function proxyConfigCurlHandle(\CurlHandle $ch): void
621604
}
622605
}
623606

607+
private function prepareCurlRequest(string $url, array|string|null $post_data = null, ?string $custom_request = null)
608+
{
609+
curl_reset($this->curl);
610+
$ch = $this->curl;
611+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->configuration->getTimeout());
612+
curl_setopt($ch, CURLOPT_TIMEOUT, $this->configuration->getTimeout());
613+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
614+
curl_setopt($ch, CURLOPT_URL, $url);
615+
616+
// post_data
617+
if (!is_null($post_data)) {
618+
// PUT REQUEST
619+
if (!is_null($custom_request) && $custom_request == 'PUT') {
620+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
621+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
622+
}
623+
if (!is_null($custom_request) && $custom_request == 'DELETE') {
624+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
625+
} else {
626+
curl_setopt($ch, CURLOPT_POST, true);
627+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
628+
}
629+
} else {
630+
if (!is_null($custom_request) && $custom_request == 'DELETE') {
631+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
632+
}
633+
}
634+
635+
return $ch;
636+
}
637+
624638
/**
625639
* setting REST API url to V2.
626640
*

src/ServiceDesk/Request/Request.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ private function map(object $data, object $target)
125125
{
126126
$mapper = new JsonMapper();
127127

128+
// Adjust settings for JsonMapper v5.0 BC
129+
if (property_exists($mapper, 'bStrictNullTypesInArrays')) {
130+
$mapper->bStrictNullTypesInArrays = false; // if you want to allow nulls in arrays
131+
}
132+
$mapper->bStrictNullTypes = false; // if you want to allow nulls
133+
$mapper->bStrictObjectTypeChecking = false; // if you want to disable strict type checking
134+
128135
return $mapper->map(
129136
$data,
130137
$target

0 commit comments

Comments
 (0)