Giter Club home page Giter Club logo

slim-debugbar's Introduction

Slim DebugBar

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

slim-debugbar's People

Contributors

yusukezzz avatar langmans avatar

Watchers

 avatar James Cloos avatar

Forkers

nigelgreenway

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.