- First commit of Negundo
This commit is contained in:
commit
69ed176b1c
18 files changed
+846
No files matched your search
@@ -0,0 +1,53 @@
|
||||
<?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 /* 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
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user