- First commit of Negundo
This commit is contained in:
commit
69ed176b1c
18 files changed
+846
No files matched your search
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Negundo\Client\Util;
|
||||
|
||||
use Negundo\Client\DataInterface;
|
||||
|
||||
class ExceptionHandler {
|
||||
|
||||
public /*DataInterface*/ $dataManipulator;
|
||||
|
||||
public function __construct(DataInterface $dataManipulator = null)
|
||||
{
|
||||
$this->dataManipulator = $dataManipulator;
|
||||
}
|
||||
|
||||
public function extractExceptionData(\Throwable $ex, array $serverData, array $postData, $dataManipulator = null) : array
|
||||
{
|
||||
$serverData = [
|
||||
'HTTPS' => $serverData['HTTPS'] ?? false,
|
||||
'HTTP_HOST' => $serverData['HTTP_HOST'] ?? "",
|
||||
'REQUEST_URI' => $serverData['REQUEST_URI'] ?? "",
|
||||
'HTTP_USER_AGENT' => $serverData['HTTP_USER_AGENT'] ?? null,
|
||||
'REMOTE_ADDR' => $serverData['REMOTE_ADDR'] ?? null,
|
||||
];
|
||||
|
||||
$post = [
|
||||
'code' => $ex->getCode(),
|
||||
'file' => $ex->getFile(),
|
||||
'line' => $ex->getLine(),
|
||||
'message' => $ex->getMessage(),
|
||||
'url' => ( ( 'on' === $serverData['HTTPS'] ) ? 'https' : 'http' ) . '://' . $serverData['HTTP_HOST'] . $serverData["REQUEST_URI"],
|
||||
'backtrace' => json_encode($ex->getTrace()),
|
||||
'backtrace_string' => $ex->getTraceAsString(),
|
||||
'source' => ( new SourceCodeFormatter() )->generateFromException($ex),
|
||||
'hits' => [
|
||||
'user_agent' => $serverData['HTTP_USER_AGENT'] ?? "???",
|
||||
'sent_at' => date('Y-m-d H:i:s'),
|
||||
'request_body_vars' => array_keys($postData),
|
||||
'remote_addr' => $serverData['REMOTE_ADDR'],
|
||||
],
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
if ( $dataManipulator ) {
|
||||
$post['data'] = $dataManipulator->getData();
|
||||
$post['hits'] = array_merge($post['hits'], $dataManipulator->getHits());
|
||||
|
||||
$dataManipulator->run($post);
|
||||
}
|
||||
|
||||
$post['data'] = json_encode($post['data'] ?? null);
|
||||
$post['hits'] = json_encode($post['hits'] ?? null);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
public function hash(\Throwable $ex) : string
|
||||
{
|
||||
return md5(implode('-', [ $ex->getMessage(), $ex->getFile(), $ex->getLine(), $ex->getCode() ]));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user