diff --git a/composer.json b/composer.json index 58cc2c0..89cf517 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,8 @@ "php": "^8.0", "ext-curl": "*", "ext-json": "*", - "netresearch/jsonmapper": "^4.2", - "monolog/monolog": "^2.0|^3.0" - }, - "suggest": { + "netresearch/jsonmapper": "^4.2|^5.0", + "monolog/monolog": "^2.0|^3.0", "vlucas/phpdotenv": "^5.0|^6.0" }, "require-dev": { diff --git a/src/JiraClient.php b/src/JiraClient.php index 6c9c558..02a7dd5 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -73,6 +73,13 @@ public function __construct(?ConfigurationInterface $configuration = null, ?Logg $this->json_mapper = new \JsonMapper(); + // Adjust settings for JsonMapper v5.0 BC + if (property_exists($this->json_mapper, 'bStrictNullTypesInArrays')) { + $this->json_mapper->bStrictNullTypesInArrays = false; // if you want to allow nulls in arrays + } + $this->json_mapper->bStrictNullTypes = false; // if you want to allow nulls + $this->json_mapper->bStrictObjectTypeChecking = false; // if you want to disable strict type checking + // Fix "\JiraRestApi\JsonMapperHelper::class" syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' $this->json_mapper->undefinedPropertyHandler = [new \JiraRestApi\JsonMapperHelper(), 'setUndefinedProperty']; @@ -198,31 +205,7 @@ public function exec(string $context, array|string|null $post_data = null, ?stri $this->log->info("Curl $custom_request: $url JsonData=".json_encode($post_data, JSON_UNESCAPED_UNICODE)); } - curl_reset($this->curl); - $ch = $this->curl; - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->configuration->getTimeout()); - curl_setopt($ch, CURLOPT_TIMEOUT, $this->configuration->getTimeout()); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_URL, $url); - - // post_data - if (!is_null($post_data)) { - // PUT REQUEST - if (!is_null($custom_request) && $custom_request == 'PUT') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - } - if (!is_null($custom_request) && $custom_request == 'DELETE') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); - } else { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - } - } else { - if (!is_null($custom_request) && $custom_request == 'DELETE') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); - } - } + $ch = $this->prepareCurlRequest($url, $post_data, $custom_request); // save HTTP Headers $curl_http_headers = [ @@ -621,6 +604,37 @@ private function proxyConfigCurlHandle(\CurlHandle $ch): void } } + private function prepareCurlRequest(string $url, array|string|null $post_data = null, ?string $custom_request = null) + { + curl_reset($this->curl); + $ch = $this->curl; + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->configuration->getTimeout()); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->configuration->getTimeout()); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_URL, $url); + + // post_data + if (!is_null($post_data)) { + // PUT REQUEST + if (!is_null($custom_request) && $custom_request == 'PUT') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + } + if (!is_null($custom_request) && $custom_request == 'DELETE') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + } else { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + } + } else { + if (!is_null($custom_request) && $custom_request == 'DELETE') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + } + } + + return $ch; + } + /** * setting REST API url to V2. * diff --git a/src/ServiceDesk/Request/Request.php b/src/ServiceDesk/Request/Request.php index 3476520..bc86923 100644 --- a/src/ServiceDesk/Request/Request.php +++ b/src/ServiceDesk/Request/Request.php @@ -125,6 +125,13 @@ private function map(object $data, object $target) { $mapper = new JsonMapper(); + // Adjust settings for JsonMapper v5.0 BC + if (property_exists($mapper, 'bStrictNullTypesInArrays')) { + $mapper->bStrictNullTypesInArrays = false; // if you want to allow nulls in arrays + } + $mapper->bStrictNullTypes = false; // if you want to allow nulls + $mapper->bStrictObjectTypeChecking = false; // if you want to disable strict type checking + return $mapper->map( $data, $target