frejfrej / zfdebug
ZFDebug 是一个适用于 PHP5 的 Zend Framework 插件,它提供有用的调试信息,以一个小条的形式显示在每个页面底部。
1.6.2
2014-06-24 08:25 UTC
Requires
This package is not auto-updated.
Last update: 2024-09-28 16:10:15 UTC
README
ZFDebug 是一个适用于 PHP5 的 Zend Framework 插件,它提供有用的调试信息,以一个小条的形式显示在每个页面底部。
时间消耗、内存使用和数据库查询次数一目了然。此外,还包括文件列表、可用视图变量和所有查询的完整 SQL 命令,分别显示在不同的面板上。
目前可用的插件有:
- 缓存:关于 Zend_Cache、APC 和 Zend OPcache(适用于 PHP 5.5)的信息。
- 数据库:Zend_Db 的 SQL 查询完整列表及其时间。
- 异常:错误和异常的处理。
- 文件:包含文件的数量和大小,以及完整列表。
- HTML:外部样式表和 JavaScript 的数量。链接到 W3C 进行验证。用于自定义内存测量。
- 日志:当前请求的时间信息、动作控制器中花费的时间以及自定义计时器的信息。还包括请求的平均时间、最小时间和最大时间。
- 变量:视图变量、请求信息和
$_COOKIE
、$_POST
和$_SESSION
的内容。 - 会话
安装与使用
要安装,请将 'ZFDebug' 文件夹放置在您的库路径中,紧挨着 Zend 文件夹旁边。然后,将以下方法添加到您的引导类中(在 ZF1.8+ 中)
protected function _initDebug()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('ZFDebug');
$options = array(
'plugins' => array('Variables',
'Database' => array('adapter' => $db),
'File' => array('basePath' => '/path/to/project'),
'Cache' => array('backend' => $cache->getBackend()),
'Exception')
);
$debug = new ZFDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
Doctrine 1 插件
以下是使用 Doctrine 插件的示例配置
protected function _initDebug()
{
if (APPLICATION_ENV === 'development') {
$options = array(
'plugins' => array(
'Variables',
'File',
'Memory',
'Time',
new ZFDebug_Controller_Plugin_Debug_Plugin_Doctrine(),
'Exception'
)
);
$ZFDebug = new ZFDebug_Controller_Plugin_Debug($options);
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin($ZFDebug);
return $ZFDebug;
}
}
Doctrine2 插件
以下是使用 Doctrine2 插件的示例配置
protected function _initDebug()
{
if (APPLICATION_ENV === 'development') {
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('ZFDebug');
$em = $this->bootstrap('doctrine')->getResource('doctrine')->getEntityManager();
$em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\DebugStack());
$options = array(
'plugins' => array(
'Variables',
'ZFDebug_Controller_Plugin_Debug_Plugin_Doctrine2' => array(
'entityManagers' => array($em),
),
'File' => array('base_path' => APPLICATION_PATH . '/application'),
//'Cache' => array('backend' => $cache->getBackend()),
'Exception',
'Html',
'Memory',
'Time',
'Registry',
)
);
$debug = new ZFDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
}
示例 Zend 插件,用于加载 ZFDebug 工具栏
某些用例可能需要您设置回调函数。特别是,这些函数发生在以下插件中:
- 缓存:当请求清理缓存时调用回调函数
- 语言:当尝试更改活动语言时调用回调
- 身份验证:当默认插件只会给出 ID 时,使用回调来检索真实用户名
您可以通过设置以下类来利用这些功能:
<?php
class Yujia_Controller_Plugin_Debug extends ZFDebug_Controller_Plugin_Debug
{
public function __construct($options = null)
{
// avoids constructing before required vars are available
}
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if (APPLICATION_ENV !== 'production') {
$auth_callback = function ($raw_user) {
// do the job for getting the real username from the raw data you would typically retrieve
};
$locale_callback = function () {
// do the job for changing locale
};
$cache_callback = function () {
// do the job for clearing the cache
};
$this->_options = array(
'image_path' => null,
'plugins' =>
array(
'Variables',
'ZFDebug_Controller_Plugin_Debug_Plugin_Doctrine2' => array(
'entityManagers' => array(\Zend_Registry::get('em')),
),
'File' => array('base_path' => APPLICATION_PATH . '/../'),
'Cache' => array('backend' => 'Zend_Cache', 'callback' => $cache_callback),
'Exception',
'Html',
'Locale' => array('callback' => $locale_callback),
'Auth' => array('user' => 'id', 'callback' => $auth_callback),
)
);
// Registering Debug plugin
parent::__construct();
}
}
}
使用 Composer
您现在可以使用依赖管理工具 Composer 安装 ZFDebug。
要使用 Composer 使用 ZFDebug,请将以下内容添加到项目中 composer.json 文件的要求列表中
"require": {
"frejfrej/zfdebug": "1.6.2"
},
运行安装命令以解决和下载依赖项
php composer.phar install
随着 github 迁移的进行,将提供更多文档。