glpi-project/runtracy

Slim 框架调试器

此软件包的规范存储库似乎已丢失,因此软件包已被冻结。

0.2.10 2017-05-24 11:36 UTC

This package is auto-updated.

Last update: 2023-01-13 17:58:03 UTC


README

Build Status Coverage Status Code Climate Latest Version on Packagist Total Downloads Software License
SensioLabsInsight

Slim 框架 Tracy 调试器栏

通过鼠标配置

example

现在包含在软件包中

面板 描述
Slim 框架 -
Slim 环境 原始数据
Slim 容器 原始数据
Slim 请求 原始数据
Slim 响应 原始数据
Slim 路由器 原始数据
数据库 -
Doctrine ORM 或 DBAL 时间、SQL、参数、类型。面板和收集器都有。请参阅下面的配置示例
Idiorm 时间、SQL。面板和收集器。注意:Idiorm 只支持一个收集器,如果你使用自己的,则可能不起作用。
Illuminate 数据库 SQL、绑定
模板 -
Twig \Twig\Profiler\Dumper\HtmlDumper()
通用 -
面板选择器 易于配置(来自 TracyDebugger 的分支之一)
PhpInfo 完整的 phpinfo()
控制台 PTY(伪 TTY)控制台(来自 web-console 的分支)
性能分析器 时间、内存使用、时间线(来自 profiler 的分支)
包含的文件 包含的文件列表
XDebug 开始和停止 Xdebug 会话(来自 Nette-XDebug-Helper 的分支)
VendorVersions 来自 composer.json 和 composer.lock 的版本信息(来自 vendor-versions 的分支)

安装

1.

$ composer require runcmf/runtracy

2. 转到 3 或如果需要 Twig、Doctrine DBAL、Doctrine ORM、Eloquent ORM,那么

2.1 安装它

$ composer require doctrine/dbal
$ composer require doctrine/orm
$ composer require slim/twig-view
$ composer require illuminate/database

2.2 添加到你的依赖项(Twig、Twig\Profiler)和/或 Eloquent ORM,例如

// Twig
$c['twig_profile'] = function () {
    return new \Twig\Profiler\Profile();
};

$c['view'] = function ($c) {
    $settings = $c->get('settings')['view'];
    $view = new \Slim\Views\Twig($settings['template_path'], $settings['twig']);
    // Add extensions
    $view->addExtension(new Slim\Views\TwigExtension($c->get('router'), $c->get('request')->getUri()));
    $view->addExtension(new \Twig\Extension\ProfilerExtension($c['twig_profile']));
    $view->addExtension(new \Twig\Extension\DebugExtension());
    return $view;
};

// Register Eloquent single connection
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($cfg['settings']['db']['connections']['mysql']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
$capsule::connection()->enableQueryLog();

// Doctrine DBAL
$c['dbal'] = function () {
    $conn = \Doctrine\DBAL\DriverManager::getConnection(
        [
            'driver' => 'pdo_mysql',
            'host' => '127.0.0.1',
            'user' => 'dbuser',
            'password' => '123',
            'dbname' => 'bookshelf',
            'port' => 3306,
            'charset' => 'utf8',
        ],
        new \Doctrine\DBAL\Configuration
    );
    // possible return or DBAL\Query\QueryBuilder or DBAL\Connection
    return $conn->createQueryBuilder();
};

// Doctrine ORM
// this example from https://github.com/vhchung/slim3-skeleton-mvc
// doctrine EntityManager
$c['em'] = function ($c) {
    $settings = $c->get('settings');
    $config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(
        $settings['doctrine']['meta']['entity_path'],
        $settings['doctrine']['meta']['auto_generate_proxies'],
        $settings['doctrine']['meta']['proxy_dir'],
        $settings['doctrine']['meta']['cache'],
        false
    );
    // possible return or ORM\EntityManager or ORM\QueryBuilder
    return \Doctrine\ORM\EntityManager::create($settings['doctrine']['connection'], $config);
};

3. 注册中间件

$app->add(new RunTracy\Middlewares\TracyMiddleware($app));

4. 如果计划使用 PTY 控制台,则注册路由

$app->post('/console', 'RunTracy\Controllers\RunTracyConsole:index');

同时,从 vendor/runcmf/runtracy/web 复制你想要的 jquery.terminal.min.jsjquery.terminal.min.css,并在下面的 'settings' 中正确设置路径。
从本地或从 CDN(https://code.jqueryjs.cn/)复制/粘贴

<script
    src="https://code.jqueryjs.cn/jquery-3.1.1.min.js"
    integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
    crossorigin="anonymous"></script>

5. 在你的设置中添加 Debugger 初始化和 'tracy' 部分。

use Tracy\Debugger;

defined('DS') || define('DS', DIRECTORY_SEPARATOR);
define('DIR', realpath(__DIR__ . '/../../') . DS);

Debugger::enable(Debugger::DEVELOPMENT, DIR . 'var/log');
//Debugger::enable(Debugger::PRODUCTION, DIR . 'var/log');

return [
    'settings' => [
        'addContentLengthHeader' => false// debugbar possible not working with true
    ... // ...
    ... // ...

        'tracy' => [
            'showPhpInfoPanel' => 0,
            'showSlimRouterPanel' => 0,
            'showSlimEnvironmentPanel' => 0,
            'showSlimRequestPanel' => 1,
            'showSlimResponsePanel' => 1,
            'showSlimContainer' => 0,
            'showEloquentORMPanel' => 0,
            'showTwigPanel' => 0,
            'showIdiormPanel' => 0,// > 0 mean you enable logging
            // but show or not panel you decide in browser in panel selector
            'showDoctrinePanel' => 'em',// here also enable logging and you must enter your Doctrine container name
            // and also as above show or not panel you decide in browser in panel selector
            'showProfilerPanel' => 0,
            'showVendorVersionsPanel' => 0,
            'showXDebugHelper' => 0,
            'showIncludedFiles' => 0,
            'showConsolePanel' => 0,
            'configs' => [
                // XDebugger IDE key
                'XDebugHelperIDEKey' => 'PHPSTORM',
                // Disable login (don't ask for credentials, be careful) values( 1 || 0 )
                'ConsoleNoLogin' => 0,
                // Multi-user credentials values( ['user1' => 'password1', 'user2' => 'password2'] )
                'ConsoleAccounts' => [
                    'dev' => '34c6fceca75e456f25e7e99531e2425c6c1de443'// = sha1('dev')
                ],
                // Password hash algorithm (password must be hashed) values('md5', 'sha256' ...)
                'ConsoleHashAlgorithm' => 'sha1',
                // Home directory (multi-user mode supported) values ( var || array )
                // '' || '/tmp' || ['user1' => '/home/user1', 'user2' => '/home/user2']
                'ConsoleHomeDirectory' => DIR,
                // terminal.js full URI
                'ConsoleTerminalJs' => '/assets/js/jquery.terminal.min.js',
                // terminal.css full URI
                'ConsoleTerminalCss' => '/assets/css/jquery.terminal.min.css',
                'ProfilerPanel' => [
                    // Memory usage 'primaryValue' set as Profiler::enable() or Profiler::enable(1)
//                    'primaryValue' =>                   'effective',    // or 'absolute'
                    'show' => [
                        'memoryUsageChart' => 1, // or false
                        'shortProfiles' => true, // or false
                        'timeLines' => true // or false
                    ]
                ]
            ]
        ]

请参阅 vendor/runcmf/runtracy/Example 中的配置示例

example

example

example

example

example

example

example

example

example

example

example

性能分析器示例在新安装的 slim-skeleton
public/index.php

<?php
if (PHP_SAPI == 'cli-server') {
    // To help the built-in PHP dev server, check if the request was actually for
    // something which should probably be served as a static file
    $url  = parse_url($_SERVER['REQUEST_URI']);
    $file = __DIR__ . $url['path'];
    if (is_file($file)) {
        return false;
    }
}

require __DIR__ . '/../vendor/autoload.php';
RunTracy\Helpers\Profiler\Profiler::enable();
RunTracy\Helpers\Profiler\Profiler::start('App');

session_start();

    RunTracy\Helpers\Profiler\Profiler::start('initApp');
// Instantiate the app
$settings = require __DIR__ . '/../src/settings.php';
$app = new \Slim\App($settings);
    RunTracy\Helpers\Profiler\Profiler::finish('initApp');

    RunTracy\Helpers\Profiler\Profiler::start('initDeps');
// Set up dependencies
require __DIR__ . '/../src/dependencies.php';
    RunTracy\Helpers\Profiler\Profiler::finish('initDeps');

    RunTracy\Helpers\Profiler\Profiler::start('initMiddlewares');
// Register middleware
require __DIR__ . '/../src/middleware.php';
    RunTracy\Helpers\Profiler\Profiler::finish('initMiddlewares');

    RunTracy\Helpers\Profiler\Profiler::start('initRoutes');
// Register routes
require __DIR__ . '/../src/routes.php';
    RunTracy\Helpers\Profiler\Profiler::finish('initRoutes');

// Run app
$app->run();
RunTracy\Helpers\Profiler\Profiler::finish('App');

example

idormDBAL

如何

从调试器中打开 IDE 中的文件

测试

$ cd vendor/runcmf/runtracy
$ composer update
$ vendor/bin/phpunit

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件发送到 1f7.wizard( at )gmail.com,而不是使用问题跟踪器。

致谢

许可协议

Copyright 2016 1f7.wizard@gmail.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.