semhoun/slim-tracy
Composer 安装命令:
composer require semhoun/slim-tracy
包简介
Tracy for Slim4 Framework Debugger
关键字:
README 文档
README
Slim Framework 4 Tracy Debugger Bar
configure it by mouse
now in package:
| Panel | Description |
|---|---|
| Slim Framework | - |
| Slim Environment | RAW data |
| Slim Container | RAW data |
| Slim Request | RAW data |
| Slim Response | RAW data |
| Slim Router | RAW data |
| DB | - |
| Doctrine ORM or DBAL | time, sql, params, types. panel & collector for both. Note: Need a Configuration instance available in DI, and must be the same used by Doctrine. |
| Illuminate Database | sql, bindings |
| Template | - |
| Twig | \Twig\Profiler\Dumper\HtmlDumper() |
| Common | - |
| PanelSelector | easy configure (part of fork from TracyDebugger) |
| PhpInfo | full phpinfo() |
| Console | PTY (pseudo TTY) console (fork from web-console) |
| Profiler | time, mem usage, timeline (fork from profiler) |
| Included Files | Included Files list |
| XDebug | start and stop a Xdebug session (fork from Nette-XDebug-Helper) |
| VendorVersions | version info from composer.json and composer.lock (fork from vendor-versions) |
Install
1.
$ composer require semhoun/slim-tracy
2. goto 3 or if need Twig, Doctrine DBAL, Doctrine ORM, Eloquent ORM then:
2.1 install it
$ composer require doctrine/dbal $ composer require doctrine/orm $ composer require slim/twig-view $ composer require illuminate/database
2.2 add to your dependencies
2.2.1 (Twig, Twig_Profiler) and/or Eloquent ORM like:
// Twig return [ Twig::class => static function (Settings $settings, \Twig\Profiler\Profile $profile): Twig { $view = Twig::create($settings->get('view.template_path'), $settings->get('view.twig')); if ($settings->get('debug')) { // Add extensions $view->addExtension(new \Twig\Extension\ProfilerExtension($profile)); $view->addExtension(new \Twig\Extension\DebugExtension()); } return $view; }, // Doctrine DBAL and ORM \Doctrine\DBAL\Connection::class => static function (Settings $settings, Doctrine\ORM\Configuration $conf): Doctrine\DBAL\Connection { return \Doctrine\DBAL\DriverManager::getConnection($settings->get('doctrine.connection'), $conf); }, // Doctrine Config used by entity manager and Tracy \Doctrine\ORM\Configuration::class => static function (Settings $settings): Doctrine\ORM\Configuration { if ($settings->get('debug')) { $queryCache = new ArrayAdapter(); $metadataCache = new ArrayAdapter(); } else { $queryCache = new PhpFilesAdapter('queries', 0, $settings->get('cache_dir')); $metadataCache = new PhpFilesAdapter('metadata', 0, $settings->get('cache_dir')); } $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCache($metadataCache); $driverImpl = new \Doctrine\ORM\Mapping\Driver\AttributeDriver($settings->get('doctrine.entity_path'), true); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCache($queryCache); $config->setProxyDir($settings->get('cache_dir') . '/proxy'); $config->setProxyNamespace('App\Proxies'); if ($settings->get('debug')) { $config->setAutoGenerateProxyClasses(true); } else { $config->setAutoGenerateProxyClasses(false); } return $config; }, // Doctrine EntityManager. EntityManager::class => static function (\Doctrine\ORM\Configuration $config, \Doctrine\DBAL\Connection $connection): EntityManager { return new EntityManager($connection, $config); }, EntityManagerInterface::class => DI\get(EntityManager::class), ]
2.2.2 Eloquent ORM like:
// Register Eloquent single connection $capsule = new \Illuminate\Database\Capsule\Manager; $capsule->addConnection($cfg['settings']['db']['connections']['mysql']); $capsule->setAsGlobal(); $capsule->bootEloquent(); $capsule::connection()->enableQueryLog();
3. register middleware If param {'configs']['Debugger'] is setted, also enable Tracy\Debugger.
$app->add(SlimTracy\Middlewares\TracyMiddleware($app, $tracySettings));
4. register route if you plan use PTY Console
$app->post('/console', 'SlimTracy\Controllers\SlimTracyConsole:index');
also copy you want jquery.terminal.min.js & jquery.terminal.min.css from vendor/semhoun/runtracy/web and correct path in 'settings' below, or set config with CDN.
'ConsoleTerminalJs' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.42.2/js/jquery.terminal.min.js', 'ConsoleTerminalCss' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.42.2/css/jquery.terminal.min.css',
add jquery from local or from CDN (https://code.jquery.com/) or copy/paste
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
5. add to your settings Debugger initialisation and 'tracy' section.
use Tracy\Debugger; 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, 'showDoctrinePanel' => 0, 'showProfilerPanel' => 0, 'showVendorVersionsPanel' => 0, 'showXDebugHelper' => 0, 'showIncludedFiles' => 0, 'showConsolePanel' => 0, 'configs' => [ // Show bar (mainly for disable bar) 'ShowBar' => 1 // XDebugger IDE key 'XDebugHelperIDEKey' => 'PHPSTORM', // Activate the console 'ConsoleEnable' => 1, // 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', 'ConsoleFromEncoding' => 'CP866', // or false '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 ] ], 'Container' => [ // Container entry name 'Doctrine' => \Doctrine\ORM\Configuration::class, // must be a configuration DBAL or ORM 'Twig' => \Twig\Profiler\Profile::class, ], 'Debugger' => [ // See \Tracy\Debugger::enable 'mode' => Debugger::Development, 'logDirectory' => null, 'email' => null ], ] ]
see config examples in vendor/semhoun/runtracy/Example
Profiler Example in slim-skeleton-mvc
public/index.php
<?php use App\Services\Settings; use DI\ContainerBuilder; // Set the absolute path to the root directory. $rootPath = realpath(__DIR__ . '/..'); // Include the composer autoloader. include_once $rootPath . '/vendor/autoload.php'; SlimTracy\Helpers\Profiler\Profiler::enable(); SlimTracy\Helpers\Profiler\Profiler::start('App'); // At this point the container has not been built. We need to load the settings manually. SlimTracy\Helpers\Profiler\Profiler::start('loadSettings'); $settings = Settings::load(); SlimTracy\Helpers\Profiler\Profiler::finish('loadSettings'); // DI Builder $containerBuilder = new ContainerBuilder(); if (! $settings->get('debug')) { // Compile and cache container. $containerBuilder->enableCompilation($settings->get('cache_dir').'/container'); } // Set up dependencies SlimTracy\Helpers\Profiler\Profiler::start('initDeps'); $containerBuilder->addDefinitions($rootPath.'/config/dependencies.php'); SlimTracy\Helpers\Profiler\Profiler::finish('initDeps'); // Build PHP-DI Container instance SlimTracy\Helpers\Profiler\Profiler::start('diBuild'); $container = $containerBuilder->build(); SlimTracy\Helpers\Profiler\Profiler::finish('diBuild'); // Instantiate the app $app = \DI\Bridge\Slim\Bridge::create($container); // Register middleware SlimTracy\Helpers\Profiler\Profiler::start('initMiddleware'); $middleware = require $rootPath . '/config/middleware.php'; $middleware($app); SlimTracy\Helpers\Profiler\Profiler::finish('initMiddleware'); // Register routes SlimTracy\Helpers\Profiler\Profiler::start('initRoutes'); $routes = require $rootPath . '/config/routes.php'; $routes($app); SlimTracy\Helpers\Profiler\Profiler::finish('initRoutes'); // Set the cache file for the routes. Note that you have to delete this file // whenever you change the routes. if (! $settings->get('debug')) { $app->getRouteCollector()->setCacheFile($settings->get('cache_dir').'/route'); } // Add the routing middleware. $app->addRoutingMiddleware(); // Add Body Parsing Middleware $app->addBodyParsingMiddleware(); // Run the app $app->run(); SlimTracy\Helpers\Profiler\Profiler::finish('App');
Tests
$ cd vendor/semhoun/runtracy
$ composer update
$ vendor/bin/phpunit
Credits
License
Copyright 2016-2022 1f7.wizard@gmail.com. Copyright 2024 Nathanaël Semhoun (nathanael@semhoun.net). 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 http://www.apache.org/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.
semhoun/slim-tracy 适用场景与选型建议
semhoun/slim-tracy 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 1.06k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「profiler」 「debugger」 「debugbar」 「Doctrine DBAL」 「debug bar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 semhoun/slim-tracy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 semhoun/slim-tracy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 semhoun/slim-tracy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
This bundle lets you use the Tracy's debug screen in combination with the the default profiler in your Symfony application.
g4 application profiler package
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
A fork of runcmf/runtracy
统计信息
- 总下载量: 1.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 28
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-08-31












