From ffd25223deaedce7d4056dfe9a34117947872156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 21 Feb 2025 10:51:15 +0200 Subject: [PATCH 1/2] Add XhguiProfilerPlugin for zend framework v1 --- contrib/zf1/XhguiProfilerPlugin.php | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 contrib/zf1/XhguiProfilerPlugin.php 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()); + } +} From 25b23bd3db7d60686f7345d8e80e312d29b27e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 21 Feb 2025 11:02:54 +0200 Subject: [PATCH 2/2] Add example init for zf1 plugin --- examples/zf1-plugin.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/zf1-plugin.php 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); +}