- First commit of Negundo
This commit is contained in:
commit
69ed176b1c
18 files changed
+846
No files matched your search
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Negundo\Client\Util;
|
||||
|
||||
use Negundo\Client\DataInterface;
|
||||
|
||||
class DumpHandler {
|
||||
|
||||
public /*DataInterface*/ $dataManipulator;
|
||||
|
||||
public function __construct(DataInterface $dataManipulator = null)
|
||||
{
|
||||
$this->dataManipulator = $dataManipulator;
|
||||
}
|
||||
|
||||
public function dumpData(...$content) : array
|
||||
{
|
||||
$backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
array_shift($backtrace);
|
||||
array_shift($backtrace);
|
||||
|
||||
$trace = $backtrace[0] ?? [
|
||||
"line" => -1,
|
||||
"file" => "unknown",
|
||||
];
|
||||
|
||||
$message = ( new SourceCodeFormatter() )->generateFromFile($trace['file'] === "unknown" ? "" : $trace['file'], $trace['line'] - 1, 1);
|
||||
|
||||
$post = [
|
||||
'file' => $trace['file'],
|
||||
'line' => $trace['line'],
|
||||
'title' => substr(strip_tags(trim(str_replace([' '], [''], $message))), 0, 255),
|
||||
'url' => ( ( 'on' === $_SERVER['HTTPS'] ?? false ) ? 'https' : 'http' ) . '://' . ( $_SERVER['HTTP_HOST'] ?? "") . ( $_SERVER["REQUEST_URI"] ?? "" ),
|
||||
'backtrace' => json_encode($backtrace),
|
||||
'source' => ( new SourceCodeFormatter() )->generateFromFile($trace['file'] === "unknown" ? "" : $trace['file'], $trace['line']),
|
||||
'data' => [
|
||||
'content' => $this->extractDumpContent(...$content),
|
||||
'sent_at' => date('Y-m-d H:i:s'),
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? null,
|
||||
'request_body' => json_encode($_POST),
|
||||
'remote_addr' => $_SERVER['REMOTE_ADDR'] ?? null,
|
||||
],
|
||||
];
|
||||
|
||||
if ( $this->dataManipulator ?? false ) {
|
||||
$post['data'] += $this->dataManipulator->getData();
|
||||
|
||||
$this->dataManipulator->run($post);
|
||||
}
|
||||
|
||||
$post['data'] = json_encode($post['data'] ?? null);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
protected function extractDumpContent(...$content) : string
|
||||
{
|
||||
ob_start();
|
||||
|
||||
var_dump( ...( $content !== [] ? $content : [null] ) );
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function hash(array $content) : string
|
||||
{
|
||||
return md5(implode('-', [ $content['file'], $content['line'], $content['title'] ]));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user