M src/Json.php => src/Json.php +7 -8
@@ 5,21 5,20 @@ namespace Thirdplace;
final class Json
{
- public static function encode($object, int $flags = 0): string
+ public static function encode($value): string
{
- return json_encode(
- $object,
- JSON_THROW_ON_ERROR
+ $flags = JSON_PRETTY_PRINT
+ | JSON_THROW_ON_ERROR
| JSON_UNESCAPED_SLASHES
| JSON_UNESCAPED_UNICODE
| JSON_INVALID_UTF8_IGNORE
- | JSON_PARTIAL_OUTPUT_ON_ERROR
- | $flags
- );
+ | JSON_PARTIAL_OUTPUT_ON_ERROR;
+
+ return json_encode($value, $flags);
}
public static function decode(string $json, bool $assoc = true)
{
return json_decode($json, $assoc, 512, JSON_THROW_ON_ERROR);
}
-}>
\ No newline at end of file
+}
D src/logger/Handler.php => src/logger/Handler.php +0 -9
@@ 1,9 0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace Thirdplace;
-
-interface Handler
-{
- public function handle(array $record): void;
-}>
\ No newline at end of file
M src/logger/SimpleLogger.php => src/logger/SimpleLogger.php +2 -7
@@ 6,13 6,8 @@ namespace Thirdplace;
final class SimpleLogger implements Logger
{
private string $name;
-
- /** @var Handler[] */
private array $handlers;
- /**
- * @param Handler[] $handlers
- */
public function __construct(string $name, array $handlers)
{
$this->name = $name;
@@ 37,7 32,7 @@ final class SimpleLogger implements Logger
public function log(int $level, string $message, array $context = []): void
{
foreach ($this->handlers as $handler) {
- $handler->handle([
+ $handler([
'name' => $this->name,
'created_at' => now(),
'level' => $level,
@@ 47,4 42,4 @@ final class SimpleLogger implements Logger
]);
}
}
-}>
\ No newline at end of file
+}
M src/logger/StreamHandler.php => src/logger/StreamHandler.php +4 -5
@@ 3,7 3,7 @@ declare(strict_types=1);
namespace Thirdplace;
-final class StreamHandler implements Handler
+final class StreamHandler
{
private $stream;
@@ 12,7 12,7 @@ final class StreamHandler implements Handler
$this->stream = $stream;
}
- public function handle(array $record): void
+ public function __invoke(array $record): void
{
if (isset($record['context']['e'])) {
/** @var \Throwable $e */
@@ 31,9 31,8 @@ final class StreamHandler implements Handler
if ($record['context'] === []) {
$record['context'] = '';
} else {
- // todo: remove dep
- $json = Json::encode($record['context'], JSON_PRETTY_PRINT) ?: '["Unable to json encode context"]';
- $record['context'] = $json;
+ $json = Json::encode($record['context']) ?: '["Unable to json encode context"]';
+ $record['context'] = " $json";
}
$result = sprintf(
M tests/container.php => tests/container.php +1 -1
@@ 17,4 17,4 @@ assertSame(2, $sut['test']);
expectException(function() use ($sut) {
$sut['foo'] = 'bar';
-});>
\ No newline at end of file
+});