From f8b018144b258b050a58b6efb8a2cd939b914da8 Mon Sep 17 00:00:00 2001
From: Dave Mc Nicoll <dave.mcnicoll@cslsj.qc.ca>
Date: Thu, 30 Mar 2023 14:14:55 -0400
Subject: [PATCH] - Latest bugfixes made to allows https without SSL
 verification (for our wildcard cert)

---
 src/Dump.php                  | 2 --
 src/Handler.php               | 5 +++--
 src/NegundoMiddleware.php     | 5 ++++-
 src/Transport/Curl.php        | 1 +
 src/Util/ExceptionHandler.php | 1 +
 5 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/Dump.php b/src/Dump.php
index c26bc9e..752239b 100644
--- a/src/Dump.php
+++ b/src/Dump.php
@@ -1,9 +1,7 @@
 <?php
 
 namespace Negundo\Client {
-
     class Dump {
-
         public static /* array */ $instances = [];
 
         # public /*string*/ $serverUrl = "http://dev.cslsj.qc.ca/debug/dump/report/%s";
diff --git a/src/Handler.php b/src/Handler.php
index 0535ab5..1a488a1 100644
--- a/src/Handler.php
+++ b/src/Handler.php
@@ -28,7 +28,7 @@ abstract class Handler {
         $this->config = $config;
 
         $this->callback = $callback;
-        $this->transport = $transport ?: new Transport\Curl();
+        $this->transport = $transport ?? new Transport\Curl();
         $this->exceptionHandler = new Util\ExceptionHandler($dataManipulator);
         $this->registerHandlers();
     }
@@ -41,6 +41,7 @@ abstract class Handler {
         
         $this->registerErrorHandler && set_error_handler(function(int $severity, string $message, string $file, int $line) {
             if ( error_reporting() & $severity ) {
+
                 $this->pushData(new \ErrorException($message, 0, $severity, $file, $line));
             }
         });
@@ -55,7 +56,7 @@ abstract class Handler {
     }
     
     public function pushData(\Throwable $ex) : ? object
-    {   
+    {
         // Make sure not to spam the server if an ErrorMessage or Exception was already sent (like inside a loop)
         $exceptionHash = $this->exceptionHandler->hash($ex);
 
diff --git a/src/NegundoMiddleware.php b/src/NegundoMiddleware.php
index a467e95..d56a3b7 100644
--- a/src/NegundoMiddleware.php
+++ b/src/NegundoMiddleware.php
@@ -38,6 +38,9 @@ class NegundoMiddleware extends Handler implements MiddlewareInterface {
 
     public function handleException(\Throwable $ex) : array 
     {
-        return $this->exceptionHandler->extractExceptionData($ex, $this->request->getServerParams(), $this->request->getParsedBody());
+        $server = isset($this->request) ? $this->request->getServerParams() : $_SERVER;
+        $body = isset($this->request) ? $this->request->getParsedBody() : $_POST;
+
+        return $this->exceptionHandler->extractExceptionData($ex, $server, $body);
     }
 }
\ No newline at end of file
diff --git a/src/Transport/Curl.php b/src/Transport/Curl.php
index e09f592..934d58e 100644
--- a/src/Transport/Curl.php
+++ b/src/Transport/Curl.php
@@ -20,6 +20,7 @@ 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);
 
         if ( ( false === curl_exec($ch) ) && $this->throwErrors ) {
             $errno = curl_errno($ch);
diff --git a/src/Util/ExceptionHandler.php b/src/Util/ExceptionHandler.php
index eceae2d..bc3c104 100644
--- a/src/Util/ExceptionHandler.php
+++ b/src/Util/ExceptionHandler.php
@@ -27,6 +27,7 @@ class ExceptionHandler {
             'code' => $ex->getCode(),
             'file' => $ex->getFile(),
             'line' => $ex->getLine(),
+            'type' => $ex::class,
             'message' => $ex->getMessage(),
             'url' => ( ( 'on' === $serverData['HTTPS'] ) ? 'https' : 'http' ) . '://' . $serverData['HTTP_HOST'] . $serverData["REQUEST_URI"],
             'backtrace' => json_encode($ex->getTrace()),