yusukezzz / slim-debugbar
Installs: 11 221
Dependents: 1
Suggesters: 0
Security: 0
Stars: 40
Watchers: 7
Forks: 8
Open Issues: 2
Requires
- php: >=5.4.0
- maximebf/debugbar: >=1.0.0
- slim/slim: 2.*
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-12-17 04:01:26 UTC
README
This middleware append PHP Debug Bar to Slim response.
Inspired by Laravel 4 DebugBar
Custom Collectors
- SlimEnvCollector (collect slim mode and version)
- SlimViewCollector (collect view variables)
- SlimRouteCollector (collect matched route information)
- SlimResponseCollector (collect response headers and cookies)
DebugBar Default Collectors
- SlimCollector
- PhpInfoCollector
- ConfigCollector
- RequestDataCollector
- TimeDataCollector
- MemoryCollector
Install
Require this package in your composer.json
"yusukezzz/slim-debugbar": "1.*"
example
<?php require '/path/to/vendor/autoload.php'; $config = []; // if you want to capture ajax requests, set instance of StorageInterface implemented. // $config['debugbar.storage'] = new \DebugBar\Storage\FileStorage('/path/to/storage'); $slim = new \Slim\Slim($config); $debugbar = new \Slim\Middleware\DebugBar(); // you can add custom collectors // $debugbar->addCollector(new MyCustomCollector()); // or use custom debugbar // $debugbar->setDebugBar(new MyCustomDebugBar()); $slim->add($debugbar); $slim->get('/', function() { echo 'Hello world!'; }); $slim->run();
Notice
- Please use real httpd (apache, nginx etc...)
- PHP builtin server does not supported.
- Available storage for ajax capturing
- Filesystem, PDO and Redis
- for more information, please refer to the official document.
- Redirection data stack
- support PHP native session only (session_start() required)
- if you want to use your own session manager, you should implement DebugBar\HttpDriverInterface.
- Reserved route for DebugBar
- /_debugbar/fonts/:file
- for fontawesome files
- /_debugbar/resources/:file
- for css, javascript
- /_debugbar/openhandler
- for previous sets of collected data
- /_debugbar/fonts/:file
Custom Session Manager example
<?php require '/path/to/vendor/autoload.php'; class MyHttpDriver implements \DebugBar\HttpDriverInterface { protected $session; protected $response; public function __construct(YourSessionManager $session, \Slim\Http\Response $response) { $this->session = $session; $this->response = $response; } public function setHeaders(array $headers) { foreach ($headers as $key => $val) { $this->response->header($key, $val); } } public function isSessionStarted() { return $this->session->isStarted(); } // You should implement other methods too } $slim = new \Slim\Slim(); $slim->container->singleton('session', function() { return new YourSessionManager(); }); $driver = new MyHttpDriver($slim->session, $slim->response); $debugbar = new \Slim\Middleware\DebugBar($driver); $slim->add($debugbar); $slim->get('/', function() { echo 'Hello world!'; }); $slim->get('/redirect', function() use ($slim) { $slim->response->redirect('/'); }); $slim->run();
Q&A
- Q. Errors in the browser's console:
Resource interpreted as Font but transferred with MIME type text/html
- A. Please read this solution
License
MIT