From 8de8aafa846a1d4d096e9da3cbec83b4764f8958 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 4 Feb 2025 08:36:14 -0500 Subject: [PATCH] - WIP on tasks --- src/Task/TaskReport.php | 18 +++++++++++++++--- src/Transport/Curl.php | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Task/TaskReport.php b/src/Task/TaskReport.php index 924b59f..073462e 100644 --- a/src/Task/TaskReport.php +++ b/src/Task/TaskReport.php @@ -2,7 +2,7 @@ namespace Negundo\Client\Task; -class TaskReport +class TaskReport implements \JsonSerializable { protected array $events = []; @@ -13,6 +13,7 @@ class TaskReport public array $data = [], ) {} + public function addData(string $name, array $data) : static { $this->data[$name][] = $data; @@ -60,13 +61,24 @@ class TaskReport return $this->data; } - public function getEvents() : array + public function getEvents(?StatusEnum $filterType = null) : array { - return $this->events; + return $filterType ? array_filter($this->events, fn($e) => StatusEnum::tryFrom($e['status']) === $filterType) : $this->events; } public function getStatus() : StatusEnum { return $this->status; } + + public function jsonSerialize(): mixed + { + return [ + 'title' => $this->getTitle(), + 'message' => $this->getMessage(), + 'status' => $this->getStatus(), + 'events' => $this->getEvents(), + 'data' => $this->getData(), + ]; + } } \ No newline at end of file diff --git a/src/Transport/Curl.php b/src/Transport/Curl.php index 4e81d34..1f59aea 100644 --- a/src/Transport/Curl.php +++ b/src/Transport/Curl.php @@ -4,7 +4,7 @@ namespace Negundo\Client\Transport; class Curl implements TransportInterface { - public $timeout = 100; + public $timeout = 4; public $throwErrors = true; @@ -21,7 +21,7 @@ class Curl implements TransportInterface { curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&')); - curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout * 200); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifySsl); $exec = curl_exec($ch);