Compare commits
3
Commits
v1.0.0
...
a552a6675e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a552a6675e | ||
|
|
5e44f36dbc | ||
|
|
4484f1c997 |
No files matched your search
@@ -2,6 +2,7 @@
|
|||||||
"name": "mcnd/negundo-client",
|
"name": "mcnd/negundo-client",
|
||||||
"description": "Negundo client which allow sending dump(), error and tasks reports",
|
"description": "Negundo client which allow sending dump(), error and tasks reports",
|
||||||
"keywords": ["negundo","dev","debug","psr15","middleware"],
|
"keywords": ["negundo","dev","debug","psr15","middleware"],
|
||||||
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@@ -13,5 +14,19 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Negundo\\Client\\": "src/"
|
"Negundo\\Client\\": "src/"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.2",
|
||||||
|
"ext-curl": "*",
|
||||||
|
"ext-json": "*"
|
||||||
|
},
|
||||||
|
"extra" : {
|
||||||
|
"lean" : {
|
||||||
|
"autoload": {
|
||||||
|
"definitions" : [
|
||||||
|
"meta/negundo.php"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use function DI\autowire, DI\create, DI\get;
|
||||||
|
|
||||||
|
use Negundo\Client\{ SoftwareConfig, Dump, Task, NegundoMiddleware };
|
||||||
|
|
||||||
|
return [
|
||||||
|
SoftwareConfig::class => create(SoftwareConfig::class)->constructor(getenv('NEGUNDO_HASH'), getenv('NEGUNDO_SERVER')),
|
||||||
|
NegundoMiddleware::class => autowire(NegundoMiddleware::class),
|
||||||
|
Dump::class => autowire(Dump::class),
|
||||||
|
Task::class => autowire(Task::class),
|
||||||
|
];
|
||||||
+7
-7
@@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
namespace Negundo\Client {
|
namespace Negundo\Client {
|
||||||
class Dump {
|
class Dump {
|
||||||
public static /* array */ $instances = [];
|
public static array $instances = [];
|
||||||
|
|
||||||
# public /*string*/ $serverUrl = "http://dev.cslsj.qc.ca/debug/dump/report/%s";
|
# public string $serverUrl = "http://dev.cslsj.qc.ca/debug/dump/report/%s";
|
||||||
|
|
||||||
protected /* SoftwareConfig */ $config;
|
protected SoftwareConfig $config;
|
||||||
|
|
||||||
protected /*array*/ $sent = [];
|
protected array $sent = [];
|
||||||
|
|
||||||
protected /* TransportInterface */ $transport;
|
protected Transport\TransportInterface $transport;
|
||||||
|
|
||||||
protected /* Util\DumpHandler */ $dumpHandler;
|
protected Util\DumpHandler $dumpHandler;
|
||||||
|
|
||||||
public function __construct(SoftwareConfig $config, ? DataInterface $dataManipulator = null, Transport\TransportInterface $transport = null)
|
public function __construct(SoftwareConfig $config, ? DataInterface $dataManipulator = null, Transport\TransportInterface $transport = null)
|
||||||
{
|
{
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -5,21 +5,21 @@ namespace Negundo\Client;
|
|||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
abstract class Handler {
|
abstract class Handler {
|
||||||
protected /* SoftwareConfig */ $config;
|
protected SoftwareConfig $config;
|
||||||
|
|
||||||
public /* bool */ $registerErrorHandler = true;
|
public bool $registerErrorHandler = true;
|
||||||
|
|
||||||
public /* bool */ $registerExceptionHandler = true;
|
public bool $registerExceptionHandler = true;
|
||||||
|
|
||||||
public /* bool */ $registerFatalErrorHandler = true;
|
public bool $registerFatalErrorHandler = true;
|
||||||
|
|
||||||
protected /*Closure*/ $callback;
|
protected Closure $callback;
|
||||||
|
|
||||||
protected /*array*/ $sent = [];
|
protected Transport\TransportInterface $transport;
|
||||||
|
|
||||||
protected /* TransportInterface */ $transport;
|
protected Util\ExceptionHandler $exceptionHandler;
|
||||||
|
|
||||||
protected /* Util\ExceptionHandler */ $exceptionHandler;
|
protected array $sent = [];
|
||||||
|
|
||||||
public abstract function handleException(\Throwable $ex) : array;
|
public abstract function handleException(\Throwable $ex) : array;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ abstract class Handler {
|
|||||||
$this->registerHandlers();
|
$this->registerHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerHandlers()
|
public function registerHandlers() : void
|
||||||
{
|
{
|
||||||
$this->registerExceptionHandler && set_exception_handler(function(\Throwable $ex) {
|
$this->registerExceptionHandler && set_exception_handler(function(\Throwable $ex) {
|
||||||
$this->pushData($ex);
|
$this->pushData($ex);
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class NegundoMiddleware extends Handler implements MiddlewareInterface {
|
|||||||
|
|
||||||
protected ServerRequestInterface $request;
|
protected ServerRequestInterface $request;
|
||||||
|
|
||||||
public $registerExceptionHandler = false;
|
public bool $registerExceptionHandler = false;
|
||||||
|
|
||||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ namespace Negundo\Client;
|
|||||||
|
|
||||||
class SoftwareConfig
|
class SoftwareConfig
|
||||||
{
|
{
|
||||||
public /*string*/ $serverUrl;
|
public string $serverUrl;
|
||||||
|
|
||||||
public /* string */ $softwareHash;
|
public string $softwareHash;
|
||||||
|
|
||||||
public function __construct(string $softwareHash, string $serverUrl)
|
public function __construct(string $softwareHash, string $serverUrl)
|
||||||
{
|
{
|
||||||
|
|||||||
+12
-8
@@ -4,15 +4,15 @@ namespace Negundo\Client {
|
|||||||
|
|
||||||
class Task {
|
class Task {
|
||||||
|
|
||||||
public static /* array */ $instances = [];
|
public static array $instances = [];
|
||||||
|
|
||||||
protected /*array*/ $sent = [];
|
protected array $sent = [];
|
||||||
|
|
||||||
protected /* TransportInterface */ $transport;
|
protected Transport\TransportInterface $transport;
|
||||||
|
|
||||||
protected /* Util\TaskHandler */ $taskHandler;
|
protected Util\TaskHandler $taskHandler;
|
||||||
|
|
||||||
protected /* SoftwareConfig */ $config;
|
protected SoftwareConfig $config;
|
||||||
|
|
||||||
public function __construct(SoftwareConfig $config, ? DataInterface $dataManipulator = null, Transport\TransportInterface $transport = null)
|
public function __construct(SoftwareConfig $config, ? DataInterface $dataManipulator = null, Transport\TransportInterface $transport = null)
|
||||||
{
|
{
|
||||||
@@ -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 = [
|
||||||
@@ -159,7 +161,7 @@ class Curl implements TransportInterface {
|
|||||||
35 => "A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be certificates (file formats, paths, permissions), passwords, and others.",
|
35 => "A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be certificates (file formats, paths, permissions), passwords, and others.",
|
||||||
36 => "The download could not be resumed because the specified offset was out of the file boundary.",
|
36 => "The download could not be resumed because the specified offset was out of the file boundary.",
|
||||||
37 => "A file given with FILE:// couldn't be opened. Most likely because the file path doesn't identify an existing file. Did you check file permissions? ",
|
37 => "A file given with FILE:// couldn't be opened. Most likely because the file path doesn't identify an existing file. Did you check file permissions? ",
|
||||||
35 => "LDAP cannot bind. LDAP bind operation failed.",
|
38 => "LDAP cannot bind. LDAP bind operation failed.",
|
||||||
39 => "LDAP search failed.",
|
39 => "LDAP search failed.",
|
||||||
41 => "Function not found. A required zlib function was not found.",
|
41 => "Function not found. A required zlib function was not found.",
|
||||||
42 => "Aborted by callback. A callback returned \"abort\" to libcurl.",
|
42 => "Aborted by callback. A callback returned \"abort\" to libcurl.",
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ use Negundo\Client\DataInterface;
|
|||||||
|
|
||||||
class DumpHandler {
|
class DumpHandler {
|
||||||
|
|
||||||
public /*DataInterface*/ $dataManipulator;
|
public DataInterface $dataManipulator;
|
||||||
|
|
||||||
public function __construct(DataInterface $dataManipulator = null)
|
public function __construct(DataInterface $dataManipulator = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use Negundo\Client\DataInterface;
|
|||||||
|
|
||||||
class ExceptionHandler {
|
class ExceptionHandler {
|
||||||
|
|
||||||
public /*DataInterface*/ $dataManipulator;
|
public ? DataInterface $dataManipulator;
|
||||||
|
|
||||||
public function __construct(DataInterface $dataManipulator = null)
|
public function __construct(DataInterface $dataManipulator = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use Negundo\Client\DataInterface;
|
|||||||
|
|
||||||
class TaskHandler {
|
class TaskHandler {
|
||||||
|
|
||||||
public /*DataInterface*/ $dataManipulator;
|
public DataInterface $dataManipulator;
|
||||||
|
|
||||||
public function __construct(DataInterface $dataManipulator = null)
|
public function __construct(DataInterface $dataManipulator = null)
|
||||||
{
|
{
|
||||||
@@ -20,8 +20,8 @@ class TaskHandler {
|
|||||||
array_shift($backtrace);
|
array_shift($backtrace);
|
||||||
|
|
||||||
$trace = $backtrace[0] ?? [
|
$trace = $backtrace[0] ?? [
|
||||||
"line" => -1,
|
|
||||||
"file" => "unknown",
|
"file" => "unknown",
|
||||||
|
"line" => -1,
|
||||||
];
|
];
|
||||||
|
|
||||||
$post = [
|
$post = [
|
||||||
|
|||||||
Reference in new issue
Block a user