Updated project.json
Added Console.php Added Utilities.php Added Validate.php Added \LogLib\Objects > Backtrace Added \LogLib\Objects > Event Added \LogLib\Objects > Options Added \LogLib\Interfaces > HandlerInterface Added \LogLib\Abstracts > LevelType.php Added \LogLib\Abstracts > ConsoleColors.php Added \LogLib\Abstracts > CallType Added project.json (NCC)
This commit is contained in:
parent
c77fb2da6b
commit
ad7dba97d2
11 changed files with 986 additions and 0 deletions
106
src/LogLib/Objects/Event.php
Normal file
106
src/LogLib/Objects/Event.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace LogLib\Objects;
|
||||
|
||||
use LogLib\Abstracts\LevelType;
|
||||
use LogLib\Classes\Utilities;
|
||||
use Throwable;
|
||||
|
||||
class Event
|
||||
{
|
||||
/**
|
||||
* The level of the event
|
||||
*
|
||||
* @see LevelType
|
||||
* @var string
|
||||
*/
|
||||
public $Level;
|
||||
|
||||
/**
|
||||
* The Unix Timestamp of when the event was created
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $Timestamp;
|
||||
|
||||
/**
|
||||
* An array of backtraces, if any, that were created when the event was created
|
||||
*
|
||||
* @var Backtrace[]|null
|
||||
*/
|
||||
public $Backtrace;
|
||||
|
||||
/**
|
||||
* The exception that was thrown, if any
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
public $Exception;
|
||||
|
||||
/**
|
||||
* The message of the event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $Message;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->Timestamp = date('Y-m-dTH:i:s.v') . (date('p') == 'Z' ? 'Z' : 'L');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an exception to the event
|
||||
*
|
||||
* @param Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
public function setException(Throwable $e): void
|
||||
{
|
||||
$this->Exception = Utilities::exceptionToArray($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the event
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'level' => ($this->Level ?? null),
|
||||
'timestamp' => ($this->Timestamp ?? null),
|
||||
'backtrace' => $this->Backtrace,
|
||||
'exception' => $this->Exception,
|
||||
'message' => ($this->Message ?? null)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new event from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return Event
|
||||
*/
|
||||
public static function fromArray(array $data): Event
|
||||
{
|
||||
$event = new Event();
|
||||
$event->Level = ($data['level'] ?? null);
|
||||
$event->Timestamp = ($data['timestamp'] ?? null);
|
||||
$event->Backtrace = ($data['backtrace'] ?? null);
|
||||
$event->Exception = ($data['exception'] ?? null);
|
||||
$event->Message = ($data['message'] ?? null);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTimestamp(): string
|
||||
{
|
||||
return $this->Timestamp;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue