|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AlecRabbit\Accessories; |
|
6
|
|
|
|
|
7
|
|
|
use AlecRabbit\Accessories\Caller\CallerData; |
|
8
|
|
|
use AlecRabbit\Accessories\Caller\CallerDataFormatter; |
|
9
|
|
|
use AlecRabbit\Accessories\Caller\Contracts\CallerConstants; |
|
10
|
|
|
use AlecRabbit\Accessories\Caller\Contracts\CallerDataFormatterInterface; |
|
11
|
|
|
use AlecRabbit\Accessories\Caller\Contracts\CallerDataInterface; |
|
12
|
|
|
|
|
13
|
|
|
class Caller implements CallerConstants |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var null|CallerDataFormatterInterface */ |
|
16
|
|
|
protected static $formatter; |
|
17
|
|
|
|
|
18
|
|
|
/** @var int */ |
|
19
|
|
|
protected static $limit = 0; |
|
20
|
|
|
|
|
21
|
|
|
/** @var int */ |
|
22
|
|
|
protected static $options = DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Static class. Private Constructor. |
|
26
|
|
|
*/ |
|
27
|
|
|
private function __construct() // @codeCoverageIgnoreStart |
|
28
|
|
|
{ |
|
29
|
|
|
} // @codeCoverageIgnoreEnd |
|
30
|
|
|
|
|
31
|
4 |
|
public static function get( |
|
32
|
|
|
?int $depth = null |
|
33
|
|
|
): CallerDataInterface { |
|
34
|
|
|
return |
|
35
|
4 |
|
new CallerData( |
|
36
|
4 |
|
self::getCallerData($depth ?? 2) |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param int $depth |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
4 |
|
private static function getCallerData(int $depth): array |
|
45
|
|
|
{ |
|
46
|
|
|
return |
|
47
|
4 |
|
debug_backtrace(static::getOptions(), static::getLimit())[++$depth] ?? self::UNDEFINED; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return CallerDataFormatterInterface |
|
52
|
|
|
*/ |
|
53
|
5 |
|
public static function getFormatter(): CallerDataFormatterInterface |
|
54
|
|
|
{ |
|
55
|
5 |
|
if (null === static::$formatter) { |
|
56
|
1 |
|
static::$formatter = new CallerDataFormatter(); |
|
57
|
|
|
} |
|
58
|
5 |
|
return static::$formatter; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param CallerDataFormatterInterface $formatter |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public static function setFormatter(CallerDataFormatterInterface $formatter): void |
|
65
|
|
|
{ |
|
66
|
1 |
|
self::$formatter = $formatter; |
|
67
|
1 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return int |
|
71
|
|
|
*/ |
|
72
|
5 |
|
public static function getLimit(): int |
|
73
|
|
|
{ |
|
74
|
5 |
|
return self::$limit; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param int $limit |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public static function setLimit(int $limit): void |
|
81
|
|
|
{ |
|
82
|
1 |
|
self::$limit = $limit; |
|
83
|
1 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return int |
|
87
|
|
|
*/ |
|
88
|
5 |
|
public static function getOptions(): int |
|
89
|
|
|
{ |
|
90
|
5 |
|
return self::$options; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param int $options |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public static function setOptions(int $options): void |
|
97
|
|
|
{ |
|
98
|
1 |
|
self::$options = $options; |
|
99
|
1 |
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|