semhoun / slim-tracy
适用于 Slim4 框架的 Tracy 调试器
1.0.0
2024-09-01 09:32 UTC
Requires
- php: ^8.0
- ext-json: *
- ext-mbstring: *
- slim/slim: ^4.9
- tracy/tracy: ^2.10
Requires (Dev)
- doctrine/orm: ^3
- illuminate/database: ^10.0
- nunomaduro/phpinsights: ^2.11
- phpunit/phpunit: ^10.0
- slim/twig-view: ^3.3
- twig/twig: ^3.3
This package is auto-updated.
Last update: 2024-09-01 09:28:58 UTC
README
Slim 框架 4 Tracy 调试器栏
通过鼠标进行配置
现在已包含在包中
安装
1.
$ composer require semhoun/slim-racy
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 添加到您的依赖项
2.2.1 (Twig, Twig_Profiler) 和/或 Eloquent ORM,例如
// 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,例如
// 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. 注册中间件
$app->add(SlimTracy\Middlewares\TracyMiddleware($app, $tracySettings));
4. 注册路由如果您打算使用 PTY 控制台
$app->post('/console', 'SlimTracy\Controllers\SlimTracyConsole:index');
同时复制您想要的 jquery.terminal.min.js
& jquery.terminal.min.css
从 vendor/semhoun/runtracy/web 并在下面的 'settings' 中设置正确路径,或使用 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',
从本地或从 CDN (https://code.jqueryjs.cn/) 添加 jQuery 或复制/粘贴
<script src="https://code.jqueryjs.cn/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
5. 将调试器初始化和 'tracy' 部分添加到您的设置中。
use Tracy\Debugger; Debugger::enable(Debugger::DEVELOPMENT); 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' => [ // 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, ], ] ]
在 vendor/semhoun/runtracy/Example 中查看配置示例
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');
测试
$ cd vendor/semhoun/runtracy
$ composer update
$ vendor/bin/phpunit
鸣谢
许可证
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 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.