rosavox/lib/alveolata/report/functions.php
2025-05-23 07:33:29 +00:00

99 lines
1.6 KiB
PHP

<?php
namespace alveolata\report;
// require_once(DIR_ALVEOLATA . '/definitions.php');
require_once(DIR_ALVEOLATA . '/string/functions.php');
require_once(DIR_ALVEOLATA . '/json/functions.php');
/**
* @author Christian Fraß <frass@greenscale.de>
*/
class struct_report
{
/**
* @var string
* @author Christian Fraß <frass@greenscale.de>
*/
public $incident;
/**
* @var array record
* @author Christian Fraß <frass@greenscale.de>
*/
public $details;
/**
* @var int $timestamp UNIX timestamp
* @author Christian Fraß <frass@greenscale.de>
*/
public $timestamp;
/**
* @param string $incident
* @param array $details
* @author Christian Fraß <frass@greenscale.de>
*/
public function __construct(
string $incident,
array $details,
int $timestamp
)
{
$this->incident = $incident;
$this->details = $details;
$this->timestamp = $timestamp;
}
}
/**
* @param string $incident
* @param array $details
* @author Christian Fraß <frass@greenscale.de>
*/
function make(
string $incident,
array $details = [],
int $timestamp = -1
) : struct_report
{
if ($timestamp < 0) {
$timestamp = time();
}
return (
new struct_report(
$incident,
$details,
$timestamp
)
);
}
/**
* @param \alveolata\report\type $report
* @return Exception
* @author Christian Fraß <frass@greenscale.de>
*/
function as_exception(
struct_report $report
) : \Exception
{
$message = \alveolata\string\coin(
'{{incident}} | {{details}}',
[
'incident' => $report->incident,
'details' => \alveolata\json\encode($report->details),
]
);
return (new \Exception($message));
}
?>