|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Core\Internal; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @internal |
|
9
|
|
|
*/ |
|
10
|
|
|
final class Tracer implements \Stringable |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Trace[] |
|
14
|
|
|
*/ |
|
15
|
|
|
private array $traces = []; |
|
16
|
|
|
|
|
17
|
410 |
|
public function __toString(): string |
|
18
|
|
|
{ |
|
19
|
410 |
|
$result = []; |
|
20
|
410 |
|
if ($this->traces !== []) { |
|
21
|
410 |
|
$result[] = 'Container trace list:'; |
|
22
|
|
|
|
|
23
|
410 |
|
foreach ($this->traces as $item) { |
|
24
|
410 |
|
$result[] = (string) $item; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
410 |
|
return \implode(PHP_EOL, $result); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
627 |
|
public function traceAutowire(string $alias, string $context = null): void |
|
32
|
|
|
{ |
|
33
|
627 |
|
$this->trace($alias, 'Autowiring', $context); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
659 |
|
public function traceBinding(string $alias, string|array|object $binding, string $context = null): void |
|
37
|
|
|
{ |
|
38
|
659 |
|
$message = match (true) { |
|
39
|
659 |
|
\is_string($binding) => \sprintf('Binding found `%s`', $binding), |
|
|
|
|
|
|
40
|
641 |
|
\is_object($binding) => \sprintf('Binding found, the instance of `%s`', $binding::class), |
|
41
|
343 |
|
default => 'Binding found' |
|
42
|
|
|
}; |
|
43
|
|
|
|
|
44
|
659 |
|
$this->trace($alias, $message, $context); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
404 |
|
public function getRootConstructedClass(): string |
|
48
|
|
|
{ |
|
49
|
404 |
|
return $this->traces[0]->alias; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
343 |
|
public function clean(): void |
|
53
|
|
|
{ |
|
54
|
343 |
|
$this->traces = []; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
736 |
|
private function trace(string $alias, string $information, string $context = null): void |
|
58
|
|
|
{ |
|
59
|
736 |
|
$this->traces[] = new Trace($alias, $information, $context); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|