- Added a process to native handler

This commit is contained in:
Dave Mc Nicoll 2024-03-01 16:48:01 +00:00
parent d94ee83230
commit 3590993925
3 changed files with 53 additions and 10 deletions

View File

@ -8,5 +8,22 @@ class NativeHandler extends Handler {
{
return $this->exceptionHandler->extractExceptionData($ex, $_SERVER, $_POST);
}
public function process(callable $callback) : mixed
{
try {
return $callback();
}
catch (\Throwable $ex)
{
$this->pushData($ex);
if ( $this->callback ?? false ) {
return call_user_func_array($this->callback, [ $ex ] );
}
else {
throw $ex;
}
}
}
}

View File

@ -4,9 +4,11 @@ namespace Negundo\Client\Transport;
class Curl implements TransportInterface {
public $timeout = 1;
public $timeout = 2;
public $throwErrors = false;
public $throwErrors = true;
public $verifySsl = false;
public $headers = [];
@ -20,22 +22,46 @@ class Curl implements TransportInterface {
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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifySsl);
$exec = curl_exec($ch);
if ( ( false === $exec ) && $this->throwErrors ) {
$errno = curl_errno($ch);
$errors = array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ]);
throw new CurlException(implode(PHP_EOL, $errors), $errno);
curl_close($ch);
throw new CurlException(implode(PHP_EOL, array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ])), $errno);
}
curl_close($ch);
return $exec;
}
public function get(string $url) : ? object
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers );
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout * 200);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifySsl);
$execute = curl_exec($ch);
if ( ( false === $execute ) && $this->throwErrors ) {
$errno = curl_errno($ch);
curl_close($ch);
throw new CurlException(implode(PHP_EOL, array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ])), $errno);
}
else {
curl_close($ch);
}
return $execute ? (object) $execute : null;
}
const CURL_ERROR = [
0 => 'CURLE_OK',
1 => 'CURLE_UNSUPPORTED_PROTOCOL',

View File

@ -22,7 +22,7 @@ class ExceptionHandler {
'HTTP_USER_AGENT' => $serverData['HTTP_USER_AGENT'] ?? null,
'REMOTE_ADDR' => $serverData['REMOTE_ADDR'] ?? null,
];
$post = [
'code' => $ex->getCode(),
'file' => $ex->getFile(),