1 | <?php |
||
19 | class CommandListener |
||
20 | { |
||
21 | private $collector; |
||
22 | private $container; |
||
23 | private $optionName; |
||
24 | private $mode; |
||
25 | private $filters = array(); |
||
26 | private $webLocation; |
||
27 | |||
28 | public function __construct(XhprofCollector $collector, ContainerInterface $container) |
||
33 | |||
34 | /** |
||
35 | * @param string $mode on|off|option |
||
36 | */ |
||
37 | public function setEnabled($mode) |
||
41 | |||
42 | /** |
||
43 | * @param string $option name of the cli option for enabled mode "option" |
||
44 | */ |
||
45 | public function setOptionName($option) |
||
49 | |||
50 | /** |
||
51 | * @param array $excludes List of regular expressions for command names to exclude |
||
52 | */ |
||
53 | public function setFilters(array $excludes) |
||
57 | |||
58 | /** |
||
59 | * Configure the base url to the xhprof web gui. |
||
60 | * |
||
61 | * @param string $webLocation |
||
62 | */ |
||
63 | public function setWebLocation($webLocation) |
||
67 | |||
68 | /** |
||
69 | * We need to add the profile enable option to all commands if we are in |
||
70 | * the parameter mode. |
||
71 | * |
||
72 | * Inspired by |
||
73 | * http://php-and-symfony.matthiasnoback.nl/2013/11/symfony2-add-a-global-option-to-console-commands-and-generate-pid-file/ |
||
74 | * |
||
75 | * @param ConsoleCommandEvent $event |
||
76 | * @return mixed |
||
77 | */ |
||
78 | private function isProfileOption(ConsoleCommandEvent $event) |
||
91 | |||
92 | /** |
||
93 | * Start the profiler if |
||
94 | * - we are not running the list or help command |
||
95 | * - the command mode is on |
||
96 | * - or the command mode if option and the option is specified |
||
97 | * |
||
98 | * @param ConsoleCommandEvent $event |
||
99 | */ |
||
100 | public function onCommand(ConsoleCommandEvent $event) |
||
134 | |||
135 | /** |
||
136 | * Trigger the collector to end the request and output the xhprof link if |
||
137 | * we where collecting. |
||
138 | * |
||
139 | * @param ConsoleTerminateEvent $event |
||
140 | */ |
||
141 | public function onTerminate(ConsoleTerminateEvent $event) |
||
155 | } |
||
156 |