Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| RelativeFilepathLogProcessor3 | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * A logger that changes file paths to be relative to the project directory. |
| 4 | * |
| 5 | * @see \BrianHenryIE\Strauss\Helpers\FileSystem::getProjectRelativePath() |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\Strauss\Helpers\Log; |
| 9 | |
| 10 | use BrianHenryIE\Strauss\Helpers\Flysystem\FileSystem; |
| 11 | use Monolog\LogRecord; |
| 12 | use Monolog\Processor\ProcessorInterface; |
| 13 | |
| 14 | class RelativeFilepathLogProcessor3 implements ProcessorInterface |
| 15 | { |
| 16 | protected FileSystem $fileSystem; |
| 17 | |
| 18 | public function __construct( |
| 19 | FileSystem $fileSystem |
| 20 | ) { |
| 21 | $this->fileSystem = $fileSystem; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Checks all context values for keys containing 'path' modifies their values to be |
| 26 | * relative to the project root. |
| 27 | * |
| 28 | */ |
| 29 | public function __invoke(LogRecord $record): LogRecord |
| 30 | { |
| 31 | |
| 32 | $context = $record->context; |
| 33 | |
| 34 | $updated = false; |
| 35 | foreach ($context as $key => $val) { |
| 36 | if (false !== stripos($key, 'path') && is_string($val)) { |
| 37 | $context[$key] = $this->fileSystem->getProjectRelativePath($val); |
| 38 | $updated = true; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return $updated ? $record->with(...['context' => $context]) : $record; |
| 43 | } |
| 44 | } |