semhoun / slim-tracy
Tracy for Slim4 Framework Debugger
Installs: 181
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 15
Open Issues: 0
Language:JavaScript
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-10-31 09:50:27 UTC
README
Slim Framework 4 Tracy Debugger Bar
configure it by mouse
now in package:
Install
1.
$ composer require semhoun/slim-racy
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
$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; 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, ], ] ]
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.