14
14
use CacheTool \Util \Formatter ;
15
15
use Symfony \Component \Console \Helper \Table ;
16
16
use Symfony \Component \Console \Input \InputInterface ;
17
+ use Symfony \Component \Console \Input \InputOption ;
17
18
use Symfony \Component \Console \Output \OutputInterface ;
18
19
19
20
class OpcacheStatusScriptsCommand extends AbstractOpcacheCommand
@@ -26,7 +27,13 @@ protected function configure()
26
27
$ this
27
28
->setName ('opcache:status:scripts ' )
28
29
->setDescription ('Show scripts in the opcode cache ' )
29
- ->setHelp ('' );
30
+ ->setHelp ('' )
31
+ ->addOption (
32
+ 'exclude ' ,
33
+ 'e ' ,
34
+ InputOption::VALUE_OPTIONAL ,
35
+ 'Exclude scripts that match this regex. Example: `.*vendor.*`. Delimiters are not needed. '
36
+ );
30
37
}
31
38
32
39
/**
@@ -39,26 +46,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int
39
46
$ info = $ this ->getCacheTool ()->opcache_get_status (true );
40
47
$ this ->ensureSuccessfulOpcacheCall ($ info );
41
48
49
+ $ exclude = $ input ->getOption ('exclude ' ) ?? null ;
50
+
42
51
$ table = new Table ($ output );
43
52
$ table
44
53
->setHeaders ([
45
54
'Hits ' ,
46
55
'Memory ' ,
47
56
'Filename '
48
57
])
49
- ->setRows ($ this ->processFilelist ($ info ['scripts ' ]))
58
+ ->setRows ($ this ->processFilelist ($ info ['scripts ' ], $ exclude ))
50
59
;
51
60
52
61
$ table ->render ();
53
62
54
63
return 0 ;
55
64
}
56
65
57
- protected function processFileList (array $ cacheList )
58
- {
66
+ protected function processFileList (
67
+ array $ cacheList ,
68
+ string $ exclude = null
69
+ ) {
59
70
$ list = [];
60
71
61
- foreach ($ cacheList as $ item ) {
72
+ $ filteredList = $ exclude ? $ this ->excludeFiles ($ cacheList , $ exclude ) : $ cacheList ;
73
+ foreach ($ filteredList as $ item ) {
62
74
$ list [] = [
63
75
number_format ($ item ['hits ' ]),
64
76
Formatter::bytes ($ item ['memory_consumption ' ]),
@@ -68,4 +80,9 @@ protected function processFileList(array $cacheList)
68
80
69
81
return $ list ;
70
82
}
83
+
84
+ protected function excludeFiles (array $ cacheList , string $ exclude = null ): array
85
+ {
86
+ return array_intersect_key ($ cacheList , array_flip (preg_grep ("( {$ exclude }) " , array_keys ($ cacheList ), \PREG_GREP_INVERT )));
87
+ }
71
88
}
0 commit comments