-
Notifications
You must be signed in to change notification settings - Fork 0
/
TraceFormatter.php
37 lines (32 loc) · 983 Bytes
/
TraceFormatter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace PTS\Tools;
class TraceFormatter
{
protected int $ignoreFilePrefixSize = 0;
public function __construct(string $ignorePath = '')
{
$path = rtrim($ignorePath, '/');
$this->ignoreFilePrefixSize = $path ? mb_strlen($path) + 1 : 0;
}
/**
* Преобразуем в более компактный вид трейс, для логов
*
* @param array[] $traces
*
* @return string[]
*/
public function formatTrace(array $traces): array
{
return array_map(function(array $t): string {
$file = $this->getFile($t['file'] ?? '');
return $file . ':' . $t['line'] . ' :: ' . $t['class'] . $t['type'] . $t['function'];
}, $traces);
}
protected function getFile(string $file): string
{
return $this->ignoreFilePrefixSize
? './' . mb_substr($file, $this->ignoreFilePrefixSize)
: $file;
}
}