如何在Zend Framework中为Doctrine2配置Bjyprofiler?

时间:2014-09-19 14:43:13

标签: php zend-framework zend-framework2

帮助,请问如何为doctrine2配置Bjyprofiler? 我找到的所有配置都是关于pdo的,我正在使用zend framework 2和doctrine2。

return array(
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
                $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array(
                    'driver'    => 'pdo',
                    'dsn'       => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'],
                    'database'  => $dbParams['database'],
                    'username'  => $dbParams['username'],
                    'password'  => $dbParams['password'],
                    'hostname'  => $dbParams['hostname'],
                ));

                if (php_sapi_name() == 'cli') {
                    $logger = new Zend\Log\Logger();
                    // write queries profiling info to stdout in CLI mode
                    $writer = new Zend\Log\Writer\Stream('php://output');
                    $logger->addWriter($writer, Zend\Log\Logger::DEBUG);
                    $adapter->setProfiler(new BjyProfiler\Db\Profiler\LoggingProfiler($logger));
                } else {
                    $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler());
                }
                if (isset($dbParams['options']) && is_array($dbParams['options'])) {
                    $options = $dbParams['options'];
                } else {
                    $options = array();
                }
                $adapter->injectProfilingStatementPrototype($options);
                return $adapter;
            },
        ),
    ),
);

感谢任何帮助。 感谢。

1 个答案:

答案 0 :(得分:0)

它对我有用。现在我在开发人员工具中获得Zend / db查询。所以你可以在你的composer.json文件中添加一些代码,如

    "bjyoungblood/bjy-profiler": "dev-master",

然后更新作曲家!

    php composer.phar update

然后让您的应用程序了解您的更改。更改您的application.config

    return array(
'modules' => array(
    'ZendDeveloperTools',
    'DoctrineModule',
    'DoctrineORMModule',
    'Application',
    'BjyProfiler'
),
'module_listener_options' => array(
    'module_paths' => array(
        './module',
        './vendor'
    ),
    'config_glob_paths' => array(
        'config/autoload/{,*.}{global,local}.php'
    )
)
);
希望它也适合你。 谢谢。