-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
196b92b
commit 3db875e
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace yii1tech\psr\log\test\support; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\LoggerTrait; | ||
|
||
/** | ||
* AbstractArrayLogger is an intermediate class for {@see ArrayLogger} creation. | ||
* | ||
* Its existence required since {@see \Psr\Log\LoggerInterface} changes signature over different PHP versions. | ||
*/ | ||
abstract class AbstractArrayLogger implements LoggerInterface | ||
{ | ||
use LoggerTrait; | ||
|
||
/** | ||
* @var array[] written log entries. | ||
*/ | ||
public $logs = []; | ||
|
||
protected function baseLog($level, $message, array $context = []): void | ||
{ | ||
$this->logs[] = [ | ||
'level' => $level, | ||
'message' => $message, | ||
'context' => $context, | ||
]; | ||
} | ||
|
||
public function flush(): array | ||
{ | ||
$logs = $this->logs; | ||
|
||
$this->logs = []; | ||
|
||
return $logs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace yii1tech\psr\log\test\support; | ||
|
||
if (version_compare(phpversion(), '8.0', '>=')) { | ||
class ArrayLogger extends AbstractArrayLogger | ||
{ | ||
public function log($level, string|\Stringable $message, array $context = []): void | ||
{ | ||
$this->baseLog($level, $message, $context); | ||
} | ||
} | ||
} else { | ||
class ArrayLogger extends AbstractArrayLogger | ||
{ | ||
public function log($level, $message, array $context = []): void | ||
{ | ||
$this->baseLog($level, $message, $context); | ||
} | ||
} | ||
} |