From 5a737c06c41c952713a284b7654b7269681a4909 Mon Sep 17 00:00:00 2001 From: Dave M Date: Mon, 22 Apr 2024 13:55:36 +0000 Subject: [PATCH] - WIP on Task scheduling interface --- src/Task.php | 4 ++-- src/Task/StatusEnum.php | 10 ++++++++++ src/Transport/Curl.php | 17 ++++++++++++----- src/Util/TaskHandler.php | 4 ++-- 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/Task/StatusEnum.php diff --git a/src/Task.php b/src/Task.php index def0e03..e42cc46 100644 --- a/src/Task.php +++ b/src/Task.php @@ -45,7 +45,7 @@ namespace Negundo\Client { namespace { if (! function_exists('ntask') ) { - function ntask(string $message, ? string $title = null, ? array $data = null) { + function ntask(string $message, ? string $title = null, ? array $data = null, ? Negundo\Client\Task\StatusEnum $status = null) { foreach (\Negundo\Client\Task::$instances as $instance) { $sent = $instance->newReport($message, $title, $data); @@ -55,4 +55,4 @@ namespace { } } } -} +} \ No newline at end of file diff --git a/src/Task/StatusEnum.php b/src/Task/StatusEnum.php new file mode 100644 index 0000000..4c65a9e --- /dev/null +++ b/src/Task/StatusEnum.php @@ -0,0 +1,10 @@ +throwErrors ) { - $errno = curl_errno($ch); - curl_close($ch); + $code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); - throw new CurlException(implode(PHP_EOL, array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ])), $errno); + if ($this->throwErrors) { + if ( false === $exec) { + $errno = curl_errno($ch); + curl_close($ch); + + throw new CurlException(implode(PHP_EOL, array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ])), $errno); + } + elseif ($code >= 400) { + throw new \Exception(sprintf("HTTP code received : $code with page content : %s", $exec)); + } } curl_close($ch); - + return $exec; } diff --git a/src/Util/TaskHandler.php b/src/Util/TaskHandler.php index 939e598..e95e93c 100644 --- a/src/Util/TaskHandler.php +++ b/src/Util/TaskHandler.php @@ -44,11 +44,11 @@ class TaskHandler { $this->dataManipulator->run($post); } - $post['data'] = json_encode($post['data'] ?? null); + $post['data'] = json_encode($post['data'] ?? null, JSON_INVALID_UTF8_IGNORE); return $post; } - + public function hash(array $content) : string { return md5(implode('-', [ $content['file'], $content['line'], $content['title'] ]));