52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Negundo\Client {
|
|
class Dump {
|
|
public static array $instances = [];
|
|
|
|
# public string $serverUrl = "http://dev.cslsj.qc.ca/debug/dump/report/%s";
|
|
|
|
protected SoftwareConfig $config;
|
|
|
|
protected array $sent = [];
|
|
|
|
protected Transport\TransportInterface $transport;
|
|
|
|
protected Util\DumpHandler $dumpHandler;
|
|
|
|
public function __construct(SoftwareConfig $config, ? DataInterface $dataManipulator = null, Transport\TransportInterface $transport = null)
|
|
{
|
|
$this->config = $config;
|
|
$this->transport = $transport ?: new Transport\Curl();
|
|
$this->dumpHandler = new Util\DumpHandler($dataManipulator);
|
|
static::$instances[] = $this;
|
|
}
|
|
|
|
public function pushData(...$content) : object|null|bool
|
|
{
|
|
$data = $this->dumpHandler->dumpData(...$content);
|
|
|
|
// Make sure not to spam the server if an ErrorMessage or Exception was already sent (like inside a loop)
|
|
$dumpHash = $this->dumpHandler->hash($data);
|
|
|
|
if ( $this->sent[$dumpHash] ?? false ) {
|
|
return null;
|
|
}
|
|
|
|
$this->sent[$dumpHash] = true;
|
|
|
|
return $this->transport->push($this->config->url('dump/report'), $data);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
if (! function_exists('ndump') ) {
|
|
function ndump(...$content) {
|
|
foreach (\Negundo\Client\Dump::$instances as $instance) {
|
|
$instance->pushData(...$content);
|
|
}
|
|
}
|
|
}
|
|
}
|