Esempio n. 1
0
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param \Pimple $mainContainer An Container instance
  */
 public function register(\Pimple $mainContainer)
 {
     $container = new \Pimple();
     $container['collector.cache'] = $mainContainer->share(function () {
         return new CacheDataCollector();
     });
     $container['collector.db'] = $mainContainer->share(function () {
         return new DatabaseDataCollector();
     });
     $container['collector.route'] = $mainContainer->share(function () {
         return new RouteDataCollector();
     });
     $container['collector.config'] = $mainContainer->share(function () use($mainContainer) {
         return new ConfigDataCollector($mainContainer['config']);
     });
     $container['bar'] = $mainContainer->share(function () use($mainContainer, $container) {
         $bar = new StandardDebugBar();
         // Defaults collectors
         $bar->addCollector($container['collector.config']);
         $bar->addCollector($container['collector.cache']);
         $bar->addCollector($container['collector.db']);
         $bar->addCollector($container['collector.route']);
         return $bar;
     });
     $container['renderer'] = $mainContainer->share(function () use($container) {
         return $container['bar']->getJavascriptRenderer();
     });
     $mainContainer['debug'] = $container;
 }
Esempio n. 2
0
 public function initCollectors()
 {
     $this->debugBar->addCollector(new DataCollector\PhpInfoCollector());
     $this->debugBar->addCollector(new DataCollector\MessagesCollector());
     $this->debugBar->addCollector(new DataCollector\RequestDataCollector());
     $this->debugBar->addCollector(new Collector\ExtendedTimeDataCollector());
     $this->debugBar->addCollector(new DataCollector\MemoryCollector());
     $this->debugBar->addCollector(new DataCollector\ExceptionsCollector());
     $this->debugBar->addCollector(new Collector\DebugBacktrace());
 }
 /**
  * Sets up Php Debug Bar
  * @throws \DebugBar\DebugBarException
  */
 private function setDebugging()
 {
     // check debug
     $this->load->config('php_debug_bar', true, true);
     $debugConfig = $this->config->item('php_debug_bar');
     $this->twig->addGlobal('debug', $debugConfig['init_debug_bar']);
     $this->debuggerEnabled = $debugConfig['init_debug_bar'];
     if ($debugConfig['init_debug_bar']) {
         $this->load->helper('url');
         $this->debugBar = new \DebugBar\StandardDebugBar();
         $this->twig->addGlobal('debugger', $this->debugBar->getJavascriptRenderer()->setBaseUrl(base_url() . 'debug/'));
         // attach doctrine hook
         if ($debugConfig['doctrine_hook']) {
             $stack = $this->doctrine->getDebugStack();
             if ($stack) {
                 $this->debugBar->addCollector(new DebugBar\Bridge\DoctrineCollector($stack));
             }
         }
     }
 }
Esempio n. 4
0
 public function register()
 {
     $this->container->add('bundle.service.debug_bar', function () {
         $debugBar = new StandardDebugBar();
         $sqlLogger = $this->container->get('db_connection')->getConfiguration()->getSQLLogger();
         $debugBar->addCollector(new DoctrineCollector($sqlLogger));
         $view = $this->container->get('service.view.view');
         if (defined('ENVIRONMENT') && ENVIRONMENT === 'development') {
             $view->loadExtension(new DebugBarExtension($debugBar));
         }
         return $debugBar;
     });
 }
 public function inject(ContainerInterface $container)
 {
     if (!$container->getParameter('debug')) {
         return;
     }
     $container[$this->name . '.session_collector'] = function () {
         return new SessionCollector();
     };
     $container[$this->name . '.timeline_collector'] = function () {
         return new TimelineCollector();
     };
     $container[$this->name . '.event_collector'] = function () {
         return new EventCollector();
     };
     $container[$this->name . '.monolog_collector'] = function (ContainerInterface $container) {
         return new MonologCollector($container->getLogger());
     };
     $container[$this->name . '.doctrine_collector'] = function (ContainerInterface $container) {
         $debugStack = new DebugStack();
         $container['doctrine.logger']->addLogger($debugStack);
         return new DoctrineCollector($debugStack);
     };
     $container[$this->name . '.debug_bar'] = function ($container) {
         $debugBar = new StandardDebugBar();
         $debugBar->addCollector($container[$this->name . '.session_collector']);
         $debugBar->addCollector($container[$this->name . '.doctrine_collector']);
         $debugBar->addCollector($container[$this->name . '.event_collector']);
         $debugBar->addCollector($container[$this->name . '.monolog_collector']);
         return $debugBar;
     };
     $container[$this->name . '.response_listener'] = new DebugBarResponseListener();
     $container[$this->name . '.assets_listener'] = new AssetsPublishEventListener();
     $container->getEventDispatcher()->addListener(KernelEvent::RESPONSE, array($container[$this->name . '.response_listener'], 'listen'));
     $container->getEventDispatcher()->addListener(FrameworkConsoleEvent::ASSETS_PUBLISH, array($container[$this->name . '.assets_listener'], 'listen'));
     //timeline collector binds to many events at once
     $container->getEventDispatcher()->addSubscriber($container[$this->name . '.timeline_collector']);
 }
 public function __invoke(ContainerInterface $container = null)
 {
     $debugBar = new StandardDebugBar();
     if ($container !== null) {
         $config = $container->has('config') ? $container->get('config') : [];
         $collectors = isset($config['phpmiddleware']['phpdebugbar']['collectors']) ? $config['phpmiddleware']['phpdebugbar']['collectors'] : [];
         foreach ($collectors as $collectorName) {
             $collector = $container->get($collectorName);
             $debugBar->addCollector($collector);
         }
         if (isset($config['phpmiddleware']['phpdebugbar']['storage']) && is_string($config['phpmiddleware']['phpdebugbar']['storage'])) {
             $storage = $container->get($config['phpmiddleware']['phpdebugbar']['storage']);
             $debugBar->setStorage($config['phpmiddleware']['phpdebugbar']['storage']);
         }
     }
     return $debugBar;
 }
 /**
  * Use the register method to register items with the container via the
  * protected $this->container property or the `getContainer` method
  * from the ContainerAwareTrait.
  */
 public function register()
 {
     $this->container->share(DebugBar::class, function () {
         $debugbar = new StandardDebugBar();
         $debugbar->addCollector(new QueryCollector());
         // Bind QueryCollector to current connection
         /* @var StandardDebugbar $debugbar */
         $connection = $this->container->get(Manager::class)->connection();
         $connection->listen(function ($query, $bindings, $time) use($debugbar, $connection) {
             $collector = $debugbar->getCollector('queries');
             $collector->addQuery((string) $query, $bindings, $time, $connection);
         });
         return $debugbar;
     });
     $this->container->share(JavascriptRenderer::class, function () {
         return $this->container->get(DebugBar::class)->getJavascriptRenderer();
     });
 }
Esempio n. 8
0
 public function route($uri = false)
 {
     if (!$uri) {
         if (empty($_SERVER['REDIRECT_URL'])) {
             if (stristr($_SERVER['REQUEST_URI'], '?') !== false) {
                 $uri = stristr($_SERVER['REQUEST_URI'], '?', true);
             } else {
                 $uri = $_SERVER['REQUEST_URI'];
             }
         } else {
             $uri = $_SERVER['REDIRECT_URL'];
         }
     }
     $context = new RequestContext($uri);
     $locator = new FileLocator(array(dirname(__FILE__) . '/../conf'));
     $router = new Router(new PhpFileLoader($locator), 'routes.php', array('cache_dir' => null), $context);
     if (!$uri) {
         $uri = $this->httpRequest->getPathInfo();
     }
     $this->route = $router->match($uri);
     $this->controller = new $this->route['class']($this);
     if (DEBUG_BAR) {
         $this->debugbar->addCollector(new ConfigCollector($this->config));
         $debugbarRenderer = $this->debugbar->getJavascriptRenderer();
         $this->debugbar["messages"]->addMessage("Debug Bar enabled");
         $this->controller->setData('debugbarRenderer', $debugbarRenderer);
     }
     //set action to index is its not set
     if (empty($this->route['action'])) {
         $this->route['action'] = $this->route['_route'] == '/' ? "index" : $this->route['_route'];
     }
     $action = $this->route['action'];
     if (!method_exists($this->controller, $action)) {
         throw new Exception('Method Not found');
     }
     $this->controller->{$action}();
 }
//include all class objects
$folder = $includesDir . "/classes";
$files = scandir($folder);
foreach ($files as $filename) {
    if ($filename != "." && $filename != "..") {
        if (strpos($filename, '.php') !== false) {
            require $folder . "/" . $filename;
        }
    }
}
if (DISPLAY_DEBUG) {
    ini_set("display_errors", 1);
    ini_set("log_errors", true);
    error_reporting(E_WARNING && E_ERROR);
    $debugbar = new StandardDebugBar();
    $debugbar->addCollector(new \DebugBar\DataCollector\MessagesCollector('database'));
    $debugbarRenderer = $debugbar->getJavascriptRenderer();
    //Initialize a global $db object (and include the logger) once to lighten memory usage
    $db = new Database($debugbar);
} else {
    ini_set("display_errors", 0);
    ini_set("log_errors", true);
    error_reporting(0);
    //Initialize a global $db object once to lighten memory usage
    $db = new Database();
}
//include all helper functions
$folder = $includesDir . "/helpers";
$files = scandir($folder);
foreach ($files as $filename) {
    if ($filename != "." && $filename != "..") {
Esempio n. 10
0
 /**
  * Adds a data collector
  *
  * @param $collector
  *
  * @return $this
  * @throws \DebugBar\DebugBarException
  */
 public function addCollector($collector)
 {
     $this->debugbar->addCollector($collector);
     return $this;
 }
Esempio n. 11
0
 /**
  * @param TraceablePDO $pdo
  */
 public function setupPdoCollector($pdo)
 {
     $collector = new PDOCollector($pdo);
     $this->debugBar->addCollector($collector);
 }
Esempio n. 12
0
 /**
  * @param $debug_stack
  * @throws \DebugBar\DebugBarException
  */
 public function loadDoctrineDebugger($debug_stack)
 {
     $this->debugBar->addCollector(new DoctrineCollector($debug_stack));
 }
Esempio n. 13
0
<?php

require 'vendor/autoload.php';
$templatesPath = dirname(__FILE__) . '/templates';
$config = ['debug' => true, 'mode' => 'development', 'view' => new \Slim\Views\Twig(), 'templates.path' => $templatesPath];
$app = new \Slim\Slim($config);
$view = $app->view();
/** Whoops errors **/
$app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
/* -- */
/** Debug Bar **/
use DebugBar\StandardDebugBar;
$debugbar = new StandardDebugBar();
$debugbar->addCollector(new DebugBar\Bridge\SlimCollector($app));
$loader = new Twig_Loader_Filesystem('.');
$env = new DebugBar\Bridge\Twig\TraceableTwigEnvironment(new Twig_Environment($loader));
$debugbar->addCollector(new DebugBar\Bridge\Twig\TwigCollector($env));
$debugbarRenderer = $debugbar->getJavascriptRenderer();
$view->appendData(['debugbarRenderer' => $debugbarRenderer]);
/* -- */
$view->parserOptions['debug'] = true;
$view->parserExtensions = array(new \Slim\Views\TwigExtension(), new \Twig_Extension_Debug());
/*$app->get('/', function() use($app) {
	$app->render('index.twig');
});*/
$app->get('/', function () use($app) {
    $em = new \App\EntityManager('news');
    $news = $em->findAll();
    $app->render('index.twig', compact('news'));
})->name('home');
/** Inject variable into twig **/
Esempio n. 14
0
 /**
  * Allows name/value pair arrays (or nested) to be logged
  * @param array $config The config file to track
  */
 public function addConfigCollector($config)
 {
     $this->debugbar->addCollector(new ConfigCollector($config));
 }