diff --git a/contrib/zf1/XhguiProfilerPlugin.php b/contrib/zf1/XhguiProfilerPlugin.php new file mode 100644 index 0000000..ccd1c8d --- /dev/null +++ b/contrib/zf1/XhguiProfilerPlugin.php @@ -0,0 +1,59 @@ + + * + * Example: + * $config = new Zend_Config(array( + * // ... + * )); + * $controller->registerPlugin(new XhguiProfilerPlugin($config), 150); + */ +class XhguiProfilerPlugin extends Zend_Controller_Plugin_Abstract +{ + /** @var Zend_Config */ + private $config; + + /** @var Profiler */ + private $profiler; + + public function __construct($config) + { + $this->config = $config; + } + + public function preDispatch(Zend_Controller_Request_Abstract $request) + { + $this->startProfiler(); + } + + public function postDispatch(Zend_Controller_Request_Abstract $request) + { + } + + private function startProfiler() + { + try { + $this->getProfiler()->start(); + } catch (ProfilerException $e) { + error_log('Profiler error: ' . $e->getMessage()); + } + } + + /** + * @return Profiler + */ + private function getProfiler() + { + if ($this->profiler !== null) { + return $this->profiler; + } + + return $this->profiler = new Profiler($this->config->toArray()); + } +} diff --git a/examples/zf1-plugin.php b/examples/zf1-plugin.php new file mode 100644 index 0000000..2ad683f --- /dev/null +++ b/examples/zf1-plugin.php @@ -0,0 +1,36 @@ + function () { + return true; + }, + + // Saver to use. + // Please note that 'pdo' and 'mongo' savers are deprecated + // Prefer 'upload' or 'file' saver. + 'save.handler' => Profiler::SAVER_UPLOAD, + + // Saving profile data by upload is only recommended with HTTPS + // endpoints that have IP whitelists applied. + // https://github.com/perftools/php-profiler#upload-saver + 'save.handler.upload' => array( + 'url' => 'https://example.com/run/import', + // The timeout option is in seconds and defaults to 3 if unspecified. + 'timeout' => 3, + // the token must match 'upload.token' config in XHGui + 'token' => 'token', + ), + )); + + $controller->registerPlugin(new XhguiProfilerPlugin($config), 150); +}