- Added some more type checking
This commit is contained in:
parent
951c93fc63
commit
4484f1c997
|
@ -22,7 +22,7 @@ namespace Negundo\Client {
|
||||||
static::$instances[] = $this;
|
static::$instances[] = $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pushData(...$content) : ? object
|
public function pushData(...$content) : object|null|bool
|
||||||
{
|
{
|
||||||
$data = $this->dumpHandler->dumpData(...$content);
|
$data = $this->dumpHandler->dumpData(...$content);
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ abstract class Handler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pushData(\Throwable $ex) : ? object
|
public function pushData(\Throwable $ex) : null|object|bool
|
||||||
{
|
{
|
||||||
// Make sure not to spam the server if an ErrorMessage or Exception was already sent (like inside a loop)
|
// Make sure not to spam the server if an ErrorMessage or Exception was already sent (like inside a loop)
|
||||||
$exceptionHash = $this->exceptionHandler->hash($ex);
|
$exceptionHash = $this->exceptionHandler->hash($ex);
|
||||||
|
|
10
src/Task.php
10
src/Task.php
|
@ -25,7 +25,7 @@ namespace Negundo\Client {
|
||||||
static::$instances[] = $this;
|
static::$instances[] = $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newReport(string $message, ? string $title = null, ? array $data = []) : ? object
|
public function newReport(string $message, ? string $title = null, ? array $data = []) : object|null|bool
|
||||||
{
|
{
|
||||||
$report = $this->taskHandler->sendReport($message, $title, $data);
|
$report = $this->taskHandler->sendReport($message, $title, $data);
|
||||||
|
|
||||||
|
@ -45,9 +45,13 @@ namespace Negundo\Client {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
if (! function_exists('ntask') ) {
|
if (! function_exists('ntask') ) {
|
||||||
function ntask(string $message, ? string $title = null, ? array $data) {
|
function ntask(string $message, ? string $title = null, ? array $data = null) {
|
||||||
foreach (\Negundo\Client\Task::$instances as $instance) {
|
foreach (\Negundo\Client\Task::$instances as $instance) {
|
||||||
$instance->newReport($message, $title, $data);
|
$sent = $instance->newReport($message, $title, $data);
|
||||||
|
|
||||||
|
if (! $sent ) {
|
||||||
|
throw new \Exception(sprintf('Could not send report titled `%s`.', $title));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Curl implements TransportInterface {
|
||||||
|
|
||||||
public $headers = [];
|
public $headers = [];
|
||||||
|
|
||||||
public function push(string $url, array $data) : ? object
|
public function push(string $url, array $data) : object|null|bool
|
||||||
{
|
{
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ class Curl implements TransportInterface {
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout * 200);
|
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout * 200);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
|
||||||
if ( ( false === curl_exec($ch) ) && $this->throwErrors ) {
|
$exec = curl_exec($ch);
|
||||||
|
|
||||||
|
if ( ( false === $exec ) && $this->throwErrors ) {
|
||||||
$errno = curl_errno($ch);
|
$errno = curl_errno($ch);
|
||||||
$errors = array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ]);
|
$errors = array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ]);
|
||||||
|
|
||||||
|
@ -31,7 +33,7 @@ class Curl implements TransportInterface {
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
return null;
|
return $exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CURL_ERROR = [
|
const CURL_ERROR = [
|
||||||
|
|
|
@ -12,7 +12,7 @@ class GuzzleClient implements TransportInterface {
|
||||||
|
|
||||||
public array $headers = [];
|
public array $headers = [];
|
||||||
|
|
||||||
public function push(string $url, array $data) : ? object
|
public function push(string $url, array $data) : object|null|bool
|
||||||
{
|
{
|
||||||
return ( new Client([
|
return ( new Client([
|
||||||
'timeout' => $this->timeout,
|
'timeout' => $this->timeout,
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
namespace Negundo\Client\Transport;
|
namespace Negundo\Client\Transport;
|
||||||
|
|
||||||
interface TransportInterface {
|
interface TransportInterface {
|
||||||
public function push(string $url, array $data) : ? object;
|
public function push(string $url, array $data) : object|null|bool;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue