File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Xhgui \Profiler \Exception \ProfilerException ;
4+ use Xhgui \Profiler \Profiler ;
5+
6+ /**
7+ * Plugin to capture profiling data using for XHGui.
8+ *
9+ * @author Elan Ruusamäe <glen@delfi.ee>
10+ *
11+ * Example:
12+ * $config = new Zend_Config(array(
13+ * // ...
14+ * ));
15+ * $controller->registerPlugin(new XhguiProfilerPlugin($config), 150);
16+ */
17+ class XhguiProfilerPlugin extends Zend_Controller_Plugin_Abstract
18+ {
19+ /** @var Zend_Config */
20+ private $ config ;
21+
22+ /** @var Profiler */
23+ private $ profiler ;
24+
25+ public function __construct ($ config )
26+ {
27+ $ this ->config = $ config ;
28+ }
29+
30+ public function preDispatch (Zend_Controller_Request_Abstract $ request )
31+ {
32+ $ this ->startProfiler ();
33+ }
34+
35+ public function postDispatch (Zend_Controller_Request_Abstract $ request )
36+ {
37+ }
38+
39+ private function startProfiler ()
40+ {
41+ try {
42+ $ this ->getProfiler ()->start ();
43+ } catch (ProfilerException $ e ) {
44+ error_log ('Profiler error: ' . $ e ->getMessage ());
45+ }
46+ }
47+
48+ /**
49+ * @return Profiler
50+ */
51+ private function getProfiler ()
52+ {
53+ if ($ this ->profiler !== null ) {
54+ return $ this ->profiler ;
55+ }
56+
57+ return $ this ->profiler = new Profiler ($ this ->config ->toArray ());
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments