diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/AbstractDocument.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/AbstractDocument.php
index 181ae6a5c..ce40df3fa 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/AbstractDocument.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/AbstractDocument.php
@@ -13,11 +13,11 @@
namespace Chevere\Components\ExceptionHandler\Documents;
+use DateTimeInterface;
use Chevere\Components\ExceptionHandler\Interfaces\DocumentInterface;
use Chevere\Components\ExceptionHandler\Interfaces\ExceptionHandlerInterface;
use Chevere\Components\ExceptionHandler\Interfaces\FormatterInterface;
use Chevere\Components\ExceptionHandler\Trace;
-use DateTimeInterface;
abstract class AbstractDocument implements DocumentInterface
{
@@ -38,9 +38,6 @@ final public function __construct(ExceptionHandlerInterface $exceptionHandler)
$this->template = $this->getTemplate();
}
- /**
- * @return string[]
- */
final public function sections(): array
{
return $this->sections;
@@ -51,11 +48,6 @@ protected function prepare(string $value): string
return $value;
}
- protected function getLineBreak(): string
- {
- return "\n\n";
- }
-
abstract public function getTemplate(): array;
abstract public function getFormatter(): FormatterInterface;
@@ -72,7 +64,7 @@ final public function toString(): string
static::TAG_ID => $this->exceptionHandler->id(),
static::TAG_DATE_TIME_UTC_ATOM => $dateTimeUtc->format(DateTimeInterface::ATOM),
static::TAG_TIMESTAMP => $dateTimeUtc->getTimestamp(),
- static::TAG_LOG_FILENAME => $this->getLogFilename(),
+ static::TAG_LOG_DESTINATION => $this->exceptionHandler->logDestination(),
static::TAG_STACK => $this->getStack(),
static::TAG_PHP_UNAME => php_uname(),
];
@@ -84,7 +76,7 @@ final public function toString(): string
return $this->prepare(
strtr(
- implode($this->getLineBreak(), array_filter($templated)),
+ implode($this->formatter->getLineBreak(), array_filter($templated)),
$this->tags
)
);
@@ -98,14 +90,6 @@ private function getExceptionCode(): string
: '';
}
- private function getLogFilename(): string
- {
- return
- $this->exceptionHandler->hasLogger()
- ? '__LOGGER_FILENAME__'
- : '/dev/null';
- }
-
private function getStack(): string
{
return
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/ConsoleDocument.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/ConsoleDocument.php
index 66f1a155e..e66c00270 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/ConsoleDocument.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/ConsoleDocument.php
@@ -39,7 +39,7 @@ public function getTemplate(): array
return [
static::SECTION_TITLE => $title,
static::SECTION_MESSAGE => $this->colorApplySection('# Message ' . static::TAG_CODE_WRAP) . "\n" . static::TAG_MESSAGE,
- static::SECTION_ID => $this->colorApplySection('# Incident ID:' . static::TAG_ID) . "\n" . 'Logged at ' . $this->colorApplyLink(static::TAG_LOG_FILENAME),
+ static::SECTION_ID => $this->colorApplySection('# Incident ID:' . static::TAG_ID) . "\n" . 'Logged at ' . $this->colorApplyLink(static::TAG_LOG_DESTINATION),
static::SECTION_TIME => $this->colorApplySection('# Time') . "\n" . static::TAG_DATE_TIME_UTC_ATOM . ' [' . static::TAG_TIMESTAMP . ']',
static::SECTION_STACK => $this->colorApplySection('# Stack trace') . "\n" . static::TAG_STACK,
static::SECTION_CLIENT => $this->colorApplySection('# Client') . "\n" . static::TAG_CLIENT_IP . ' ' . static::TAG_CLIENT_USER_AGENT,
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/HtmlDocument.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/HtmlDocument.php
index ce0a3f370..afc072c0f 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/HtmlDocument.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/HtmlDocument.php
@@ -48,7 +48,7 @@ public function getTemplate(): array
static::SECTION_TITLE => $this->wrapTitle(static::TAG_TITLE . ' in ' . static::TAG_FILE_LINE . ''),
static::SECTION_MESSAGE => $this->wrapSectionTitle('# Message ' . static::TAG_CODE_WRAP) . "\n" . $this->wrapContent(static::TAG_MESSAGE),
static::SECTION_TIME => $this->wrapSectionTitle('# Time') . "\n" . $this->wrapContent(static::TAG_DATE_TIME_UTC_ATOM . ' [' . static::TAG_TIMESTAMP . ']'),
- static::SECTION_ID => $this->wrapSectionTitle('# Incident ID:' . static::TAG_ID) . "\n" . $this->wrapContent('Logged at ' . static::TAG_LOG_FILENAME),
+ static::SECTION_ID => $this->wrapSectionTitle('# Incident ID:' . static::TAG_ID) . "\n" . $this->wrapContent('Logged at ' . static::TAG_LOG_DESTINATION),
static::SECTION_STACK => $this->wrapSectionTitle('# Stack trace') . "\n" . $this->wrapContent(static::TAG_STACK),
static::SECTION_CLIENT => $this->wrapSectionTitle('# Client') . "\n" . $this->wrapContent(static::TAG_CLIENT_IP . ' ' . static::TAG_CLIENT_USER_AGENT),
static::SECTION_REQUEST => $this->wrapSectionTitle('# Request') . "\n" . $this->wrapContent(static::TAG_SERVER_PROTOCOL . ' ' . static::TAG_REQUEST_METHOD . ' ' . static::TAG_URI),
@@ -61,11 +61,6 @@ public function getTemplate(): array
}
}
- protected function getLineBreak(): string
- {
- return "\n
\n";
- }
-
protected function prepare(string $value): string
{
$preDocument = strtr(static::HTML_TEMPLATE, [
@@ -84,9 +79,7 @@ private function wrapTitle(string $value): string
private function wrapSectionTitle(string $value): string
{
- $value = str_replace('# ', $this->wrapHidden('# '), $value);
-
- return '
' . $value . '
';
+ return '' . str_replace('# ', $this->wrapHidden('# '), $value) . '
';
}
private function wrapHidden(string $value): string
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/PlainDocument.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/PlainDocument.php
index 33eaa8ace..2e752ba62 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/PlainDocument.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Documents/PlainDocument.php
@@ -32,7 +32,7 @@ public function getTemplate(): array
static::SECTION_TITLE => static::TAG_TITLE . ' in ' . static::TAG_FILE_LINE,
static::SECTION_MESSAGE => '# Message ' . static::TAG_CODE_WRAP . "\n" . '%message%',
static::SECTION_TIME => '# Time' . "\n" . static::TAG_DATE_TIME_UTC_ATOM . ' [' . static::TAG_TIMESTAMP . ']',
- static::SECTION_ID => '# Incident ID:' . static::TAG_ID . "\n" . 'Logged at ' . static::TAG_LOG_FILENAME,
+ static::SECTION_ID => '# Incident ID:' . static::TAG_ID . "\n" . 'Logged at ' . static::TAG_LOG_DESTINATION,
static::SECTION_STACK => '# Stack trace' . "\n" . static::TAG_STACK,
static::SECTION_CLIENT => '# Client' . "\n" . static::TAG_CLIENT_IP . ' ' . static::TAG_CLIENT_USER_AGENT,
static::SECTION_REQUEST => '# Request' . "\n" . static::TAG_SERVER_PROTOCOL . ' ' . static::TAG_REQUEST_METHOD . ' ' . static::TAG_URI,
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Exception.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Exception.php
index 67d9ea89c..6ce7161d2 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Exception.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Exception.php
@@ -31,8 +31,6 @@ final class Exception implements ExceptionInterface
private string $type;
- private string $loggerLevel;
-
private string $message;
private string $file;
@@ -59,7 +57,7 @@ public function __construct(\Exception $exception)
$this->severity = ExceptionInterface::DEFAULT_ERROR_TYPE;
}
$this->assertSeverity();
- $this->loggerLevel = ExceptionInterface::ERROR_LEVELS[$this->severity];
+ // $this->loggerLevel = ExceptionInterface::ERROR_LEVELS[$this->severity];
$this->type = ExceptionInterface::ERROR_TYPES[$this->severity];
$this->message = $exception->getMessage();
$this->file = $exception->getFile();
@@ -99,14 +97,6 @@ public function type(): string
return $this->type;
}
- /**
- * {@inheritdoc}
- */
- public function loggerLevel(): string
- {
- return $this->loggerLevel;
- }
-
/**
* {@inheritdoc}
*/
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/ExceptionHandler.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/ExceptionHandler.php
index 48ffd1f6b..a394cd236 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/ExceptionHandler.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/ExceptionHandler.php
@@ -14,19 +14,13 @@
namespace Chevere\Components\ExceptionHandler;
use BadMethodCallException;
-use DateTime;
use DateTimeZone;
use DateTimeInterface;
-use Chevere\Components\App\Instances\RuntimeInstance;
-use Chevere\Components\ExceptionHandler\Documents\ConsoleDocument;
-use Chevere\Components\ExceptionHandler\Formatters\ConsoleFormatter;
+use DateTimeImmutable;
use Chevere\Components\ExceptionHandler\Interfaces\ExceptionHandlerInterface;
use Chevere\Components\ExceptionHandler\Interfaces\ExceptionInterface;
use Chevere\Components\Http\Interfaces\RequestInterface;
use Chevere\Components\Message\Message;
-use Chevere\Components\Runtime\Interfaces\RuntimeInterface;
-use DateTimeImmutable;
-use Monolog\Logger;
/**
* The Chevere exception handler.
@@ -39,17 +33,15 @@ final class ExceptionHandler implements ExceptionHandlerInterface
private string $id;
- // private RuntimeInterface $runtime;
-
private RequestInterface $request;
- private Logger $logger;
-
- private string $loggerFilename;
-
private bool $isDebug = false;
+ private string $logDestination = '/dev/null';
+
/**
+ * Creates a new instance.
+ *
* @param mixed $args Arguments passed to the error exception (severity, message, file, line; Exception)
*/
public function __construct(\Exception $exception)
@@ -59,25 +51,33 @@ public function __construct(\Exception $exception)
$this->id = uniqid('', true);
}
- public static function function($exception): void
- {
- }
-
+ /**
+ * {@inheritdoc}
+ */
public function dateTimeUtc(): DateTimeInterface
{
return $this->dateTimeUtc;
}
+ /**
+ * {@inheritdoc}
+ */
public function exception(): ExceptionInterface
{
return $this->exception;
}
+ /**
+ * {@inheritdoc}
+ */
public function id(): string
{
return $this->id;
}
+ /**
+ * {@inheritdoc}
+ */
public function withIsDebug(bool $isDebug): ExceptionHandlerInterface
{
$new = clone $this;
@@ -86,6 +86,9 @@ public function withIsDebug(bool $isDebug): ExceptionHandlerInterface
return $new;
}
+ /**
+ * {@inheritdoc}
+ */
public function isDebug(): bool
{
return $this->isDebug;
@@ -102,6 +105,9 @@ public function withRequest(RequestInterface $request): ExceptionHandlerInterfac
return $new;
}
+ /**
+ * {@inheritdoc}
+ */
public function hasRequest(): bool
{
return isset($this->request);
@@ -117,24 +123,17 @@ public function request(): RequestInterface
return $this->request;
}
- public function withLogger(Logger $logger): ExceptionHandlerInterface
+ public function withLogDestination(string $logDestination): ExceptionHandlerInterface
{
$new = clone $this;
- $new->logger = $logger;
+ $new->logDestination = $logDestination;
return $new;
}
- public function hasLogger(): bool
- {
- return isset($this->logger);
- }
-
- public function logger(): Logger
+ public function logDestination(): string
{
- $this->assertPropertyMethod();
-
- return $this->logger;
+ return $this->logDestination;
}
private function assertPropertyMethod(): void
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/AbstractFormatter.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/AbstractFormatter.php
index 54f1624b3..e34f42a8a 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/AbstractFormatter.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/AbstractFormatter.php
@@ -59,4 +59,12 @@ public function getHr(): string
{
return '------------------------------------------------------------';
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getLineBreak(): string
+ {
+ return "\n\n";
+ }
}
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/HtmlFormatter.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/HtmlFormatter.php
index 421168b1a..aa53933fe 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/HtmlFormatter.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Formatters/HtmlFormatter.php
@@ -36,4 +36,9 @@ public function getHr(): string
{
return '------------------------------------------------------------
';
}
+
+ public function getLineBreak(): string
+ {
+ return "\n
\n";
+ }
}
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/DocumentInterface.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/DocumentInterface.php
index 4c45619ce..d2d2ed2f7 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/DocumentInterface.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/DocumentInterface.php
@@ -31,7 +31,7 @@ interface DocumentInterface
const TAG_FILE_LINE = '%fileLine%';
const TAG_DATE_TIME_UTC_ATOM = '%dateTimeUtcAtom%';
const TAG_TIMESTAMP = '%timestamp%';
- const TAG_LOG_FILENAME = '%logFilename%';
+ const TAG_LOG_DESTINATION = '%logDestination%';
const TAG_STACK = '%stack%';
const TAG_CLIENT_IP = '%clientIp%';
const TAG_CLIENT_USER_AGENT = '%clientUserAgent%';
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionHandlerInterface.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionHandlerInterface.php
index b2355bc6d..8d89d3952 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionHandlerInterface.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionHandlerInterface.php
@@ -13,34 +13,67 @@
namespace Chevere\Components\ExceptionHandler\Interfaces;
-use Chevere\Components\Http\Interfaces\RequestInterface;
-use Chevere\Components\Runtime\Interfaces\RuntimeInterface;
use DateTimeInterface;
-use Monolog\Logger;
+use Chevere\Components\Http\Interfaces\RequestInterface;
interface ExceptionHandlerInterface
{
- public function __construct(\Exception $exception);
-
+ /**
+ * Provides access to the instance DateTime UTC.
+ */
public function dateTimeUtc(): DateTimeInterface;
+ /**
+ * Provides access to the instance exception.
+ */
public function exception(): ExceptionInterface;
+ /**
+ * Provides access to the instance id.
+ */
public function id(): string;
+ /**
+ * Return an instance with the specified debug flag.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified debug flag.
+ */
public function withIsDebug(bool $isDebug): ExceptionHandlerInterface;
+ /**
+ * Provides access to the instance debug flag.
+ */
public function isDebug(): bool;
+ /**
+ * Return an instance with the specified RequestInterface.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified RequestInterface.
+ */
public function withRequest(RequestInterface $request): ExceptionHandlerInterface;
+ /**
+ * Returns a boolean indicating whether the instance has a RequestInterface.
+ */
public function hasRequest(): bool;
+ /**
+ * Provides access to the RequestInterface instance.
+ */
public function request(): RequestInterface;
- public function withLogger(Logger $logger): ExceptionHandlerInterface;
-
- public function hasLogger(): bool;
-
- public function logger(): Logger;
+ /**
+ * Return an instance with the specified log destination.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified log destination.
+ */
+ public function withLogDestination(string $logDestination): ExceptionHandlerInterface;
+
+ /**
+ * Provides access to the instance log destination.
+ */
+ public function logDestination(): string;
}
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionInterface.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionInterface.php
index 547781620..81e9f58d9 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionInterface.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/ExceptionInterface.php
@@ -57,21 +57,43 @@ interface ExceptionInterface
E_USER_DEPRECATED => LogLevel::NOTICE,
];
+ /**
+ * Provides access to the exception class name.
+ */
public function className(): string;
+ /**
+ * Provides access to the exception code.
+ */
public function code(): int;
+ /**
+ * Provides access to the exception severity.
+ */
public function severity(): int;
+ /**
+ * Provides access to the exception type.
+ */
public function type(): string;
- public function loggerLevel(): string;
-
+ /**
+ * Provides access to the exception message.
+ */
public function message(): string;
+ /**
+ * Provides access to the exception file.
+ */
public function file(): string;
+ /**
+ * Provides access to the exception line.
+ */
public function line(): int;
+ /**
+ * Provides access to the exception trace.
+ */
public function trace(): array;
}
diff --git a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/FormatterInterface.php b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/FormatterInterface.php
index 032fc9885..8c2e22163 100644
--- a/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/FormatterInterface.php
+++ b/Chevereto-Chevere/Chevere/Components/ExceptionHandler/Interfaces/FormatterInterface.php
@@ -35,4 +35,6 @@ public function getVarDumpFormatter(): VarDumpFormatterInterface;
public function getTraceEntryTemplate(): string;
public function getHr(): string;
+
+ public function getLineBreak(): string;
}