yusukezzz/slim-debugbar

1.1.2 2015-08-03 03:17 UTC

This package is not auto-updated.

Last update: 2024-10-08 03:05:36 UTC


README

Latest Stable Version Build Status

This middleware append PHP Debug Bar to Slim response.

Inspired by Laravel 4 DebugBar

Screenshot

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
  • 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

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

License

MIT