tavy315/zfdebug

此包已废弃,不再维护。未建议替代包。

ZFDebug是PHP5的Zend Framework插件,在每页底部的小栏中提供有用的调试信息。

1.7.6 2017-10-05 14:45 UTC

This package is not auto-updated.

Last update: 2020-01-24 15:47:45 UTC


README

ZFDebug是PHP5的Zend Framework插件,在每页底部的小栏中提供有用的调试信息。

时间消耗、内存使用和数据库查询次数一目了然。此外,还包括单独的面板,显示包含的文件、可用的视图变量和所有查询的完整SQL命令

目前可用的插件有

  • 缓存:关于Zend_Cache、APC和Zend OPcache(PHP 5.5)的信息。
  • 数据库:从Zend_Db的完整SQL查询列表及其时间。
  • 异常:错误和异常的处理。
  • 文件:包含的文件数量和大小,完整列表。
  • HTML:外部样式表和javascript的数量。链接到W3C进行验证。用于自定义内存测量。
  • 日志:当前请求的计时信息、动作控制器中的时间消耗和自定义计时器。还包括请求的平均、最小和最大时间。
  • 会话
  • 变量:视图变量、请求信息和$_COOKIE、$_POST和$_SESSION的内容

安装

{
    "minimum-stability": "dev",
    "require": {
        "tavy315/zfdebug" : "dev-master"
    }
}

使用Composer

您现在可以使用Composer依赖管理工具安装ZFDebug。

要使用Composer与ZFDebug一起使用,请将以下内容添加到项目composer.json文件中的require列表中

"require": {
    "tavy315/zfdebug": "1.*"
},

运行安装命令以解析和下载依赖项

php composer.phar install

使用

要安装,将'ZFDebug'文件夹放在您的库路径中,紧邻Zend文件夹旁边。然后向您的引导类(在ZF1.8+)中添加以下方法

protected function _initZFDebug()
{
    $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);
}

加载ZFDebug工具栏的示例Zend插件

某些用例可能需要您设置回调函数。特别是,这些函数在以下插件中发生

  • 缓存:当请求清理缓存时调用回调函数
  • 语言:当尝试更改活动语言时调用回调
  • 身份验证:当默认插件只能提供ID时,用于检索真实用户名的回调

您可以通过设置以下类来利用这些功能

<?php
class Application_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',
                    '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();
        }
    }
}

Doctrine 1插件

以下是使用Doctrine插件的示例配置

protected function _initZFDebug()
{
    if (APPLICATION_ENV === 'development') {
        $options = array(
            'plugins' => array(
                'Variables',
                'File',
                'Memory',
                'Time',
                'Doctrine1',
                'Exception'
            )
        );

        $ZFDebug = new \ZFDebug\Controller\Plugin\Debug($options);
        $frontController = \Zend_Controller_Front::getInstance();
        $frontController->registerPlugin($ZFDebug);

        return $ZFDebug;
    }
}

Doctrine2插件

以下是使用Doctrine2插件的示例配置

protected function _initZFDebug()
{
    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',
                'Doctrine2'	=> array(
                    'entityManagers' => array($em),
                ),
                'File' => array(
                    'basePath' => 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);
    }
}

随着GitHub迁移的进展,将提供更多文档。