1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Collector; |
6
|
|
|
|
7
|
|
|
final class FilesystemStreamCollector implements CollectorInterface, IndexCollectorInterface |
8
|
|
|
{ |
9
|
|
|
use CollectorTrait; |
10
|
|
|
|
11
|
|
|
public function __construct(private array $ignoredPathPatterns = [], private array $ignoredClasses = []) |
12
|
|
|
{ |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array[] |
17
|
|
|
*/ |
18
|
|
|
private array $operations = []; |
19
|
|
|
|
20
|
|
|
public function getCollected(): array |
21
|
|
|
{ |
22
|
|
|
return array_map('array_values', $this->operations); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function startup(): void |
26
|
|
|
{ |
27
|
|
|
$this->isActive = true; |
28
|
|
|
FilesystemStreamProxy::register(); |
29
|
|
|
FilesystemStreamProxy::$collector = $this; |
30
|
|
|
FilesystemStreamProxy::$ignoredPathPatterns = $this->ignoredPathPatterns; |
31
|
|
|
FilesystemStreamProxy::$ignoredClasses = $this->ignoredClasses; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function shutdown(): void |
35
|
|
|
{ |
36
|
|
|
FilesystemStreamProxy::unregister(); |
37
|
|
|
FilesystemStreamProxy::$collector = null; |
38
|
|
|
FilesystemStreamProxy::$ignoredPathPatterns = []; |
39
|
|
|
FilesystemStreamProxy::$ignoredClasses = []; |
40
|
|
|
|
41
|
|
|
$this->reset(); |
42
|
|
|
$this->isActive = false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function collect(string $operation, string $path, array $args): void |
46
|
|
|
{ |
47
|
|
|
if (!$this->isActive()) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->operations[$operation][] = [ |
52
|
|
|
'path' => $path, |
53
|
|
|
'args' => $args, |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getIndexData(): array |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
'fs_stream' => array_merge( |
61
|
|
|
...array_map( |
62
|
|
|
fn (string $operation) => [$operation => count($this->operations[$operation])], |
63
|
|
|
array_keys($this->operations) |
64
|
|
|
) |
65
|
|
|
), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function reset(): void |
70
|
|
|
{ |
71
|
|
|
$this->operations = []; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|