Exemplo n.º 1
0
 /**
  * Boot the debugbar (add collectors, renderer and listener)
  */
 public function boot()
 {
     if ($this->booted) {
         return;
     }
     $debugbar = $this;
     $app = $this->app;
     if ($this->app['config']->get('laravel-debugbar::config.storage.enabled')) {
         $path = $this->app['config']->get('laravel-debugbar::config.storage.path');
         $storage = new FilesystemStorage($this->app['files'], $path);
         $debugbar->setStorage($storage);
     }
     if ($this->shouldCollect('phpinfo', true)) {
         $this->addCollector(new PhpInfoCollector());
     }
     if ($this->shouldCollect('messages', true)) {
         $this->addCollector(new MessagesCollector());
     }
     if ($this->shouldCollect('time', true)) {
         $this->addCollector(new TimeDataCollector());
         $this->app->booted(function () use($debugbar) {
             if (defined('LARAVEL_START')) {
                 $debugbar['time']->addMeasure('Booting', LARAVEL_START, microtime(true));
             }
         });
         //Check if App::before is already called..
         if (version_compare($app::VERSION, '4.1', '>=') && $this->app->isBooted()) {
             $debugbar->startMeasure('application', 'Application');
         } else {
             $this->app->before(function () use($debugbar) {
                 $debugbar->startMeasure('application', 'Application');
             });
         }
         $this->app->after(function () use($debugbar) {
             $debugbar->stopMeasure('application');
             $debugbar->startMeasure('after', 'After application');
         });
     }
     if ($this->shouldCollect('memory', true)) {
         $this->addCollector(new MemoryCollector());
     }
     if ($this->shouldCollect('exceptions', true)) {
         try {
             $exceptionCollector = new ExceptionsCollector();
             if (method_exists($exceptionCollector, 'setChainExceptions')) {
                 $exceptionCollector->setChainExceptions($this->app['config']->get('laravel-debugbar::config.options.exceptions.chain', true));
             }
             $this->addCollector($exceptionCollector);
             $this->app->error(function (Exception $exception) use($exceptionCollector) {
                 $exceptionCollector->addException($exception);
             });
         } catch (\Exception $e) {
         }
     }
     if ($this->shouldCollect('laravel', false)) {
         $this->addCollector(new LaravelCollector($this->app));
     }
     if ($this->shouldCollect('default_request', false)) {
         $this->addCollector(new RequestDataCollector());
     }
     if ($this->shouldCollect('events', false) and isset($this->app['events'])) {
         try {
             $this->addCollector(new MessagesCollector('events'));
             $dispatcher = $this->app['events'];
             $dispatcher->listen('*', function () use($debugbar, $dispatcher) {
                 if (method_exists($dispatcher, 'firing')) {
                     $event = $dispatcher->firing();
                 } else {
                     $args = func_get_args();
                     $event = end($args);
                 }
                 $debugbar['events']->info("Received event: " . $event);
             });
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add EventCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('views', true) and isset($this->app['events'])) {
         try {
             $collectData = $this->app['config']->get('laravel-debugbar::config.options.views.data', true);
             $this->addCollector(new ViewCollector($collectData));
             $this->app['events']->listen('composing:*', function ($view) use($debugbar) {
                 $debugbar['views']->addView($view);
             });
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add ViewCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('route')) {
         try {
             if (version_compare($app::VERSION, '4.1', '>=')) {
                 $this->addCollector($this->app->make('Barryvdh\\Debugbar\\DataCollector\\IlluminateRouteCollector'));
             } else {
                 $this->addCollector($this->app->make('Barryvdh\\Debugbar\\DataCollector\\SymfonyRouteCollector'));
             }
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add RouteCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('log', true)) {
         try {
             if ($this->hasCollector('messages')) {
                 $logger = new MessagesCollector('log');
                 $this['messages']->aggregate($logger);
                 $this->app['log']->listen(function ($level, $message, $context) use($logger) {
                     try {
                         $logMessage = (string) $message;
                         if (mb_check_encoding($logMessage, 'UTF-8')) {
                             $logMessage .= !empty($context) ? ' ' . json_encode($context) : '';
                         } else {
                             $logMessage = "[INVALID UTF-8 DATA]";
                         }
                     } catch (\Exception $e) {
                         $logMessage = "[Exception: " . $e->getMessage() . "]";
                     }
                     $logger->addMessage('[' . date('H:i:s') . '] ' . "LOG.{$level}: " . $logMessage, $level, false);
                 });
             } else {
                 $this->addCollector(new MonologCollector($this->app['log']->getMonolog()));
             }
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add LogsCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('db', true) and isset($this->app['db'])) {
         $db = $this->app['db'];
         if ($debugbar->hasCollector('time') && $this->app['config']->get('laravel-debugbar::config.options.db.timeline', false)) {
             $timeCollector = $debugbar->getCollector('time');
         } else {
             $timeCollector = null;
         }
         $queryCollector = new QueryCollector($timeCollector);
         if ($this->app['config']->get('laravel-debugbar::config.options.db.with_params')) {
             $queryCollector->setRenderSqlWithParams(true);
         }
         if ($this->app['config']->get('laravel-debugbar::config.options.db.backtrace')) {
             $queryCollector->setFindSource(true);
         }
         $this->addCollector($queryCollector);
         try {
             $db->listen(function ($query, $bindings, $time, $connectionName) use($db, $queryCollector) {
                 $connection = $db->connection($connectionName);
                 if (!method_exists($connection, 'logging') || $connection->logging()) {
                     $queryCollector->addQuery((string) $query, $bindings, $time, $connection);
                 }
             });
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add listen to Queries for Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('mail', true)) {
         try {
             $mailer = $this->app['mailer']->getSwiftMailer();
             $this->addCollector(new SwiftMailCollector($mailer));
             if ($this->app['config']->get('laravel-debugbar::config.options.mail.full_log') and $this->hasCollector('messages')) {
                 $this['messages']->aggregate(new SwiftLogCollector($mailer));
             }
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add MailCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('logs', false)) {
         try {
             $file = $this->app['config']->get('laravel-debugbar::config.options.logs.file');
             $this->addCollector(new LogsCollector($file));
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add LogsCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('files', false)) {
         $this->addCollector(new FilesCollector($app));
     }
     if ($this->shouldCollect('auth', false)) {
         try {
             $authCollector = new AuthCollector($app['auth']);
             $authCollector->setShowName($this->app['config']->get('laravel-debugbar::config.options.auth.show_name'));
             $this->addCollector($authCollector);
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add AuthCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     $renderer = $this->getJavascriptRenderer();
     $renderer->setBaseUrl($this->app['url']->asset('packages/maximebf/php-debugbar'));
     $renderer->setIncludeVendors($this->app['config']->get('laravel-debugbar::config.include_vendors', true));
     $this->booted = true;
 }
Exemplo n.º 2
0
 /**
  * Boot the debugbar (add collectors, renderer and listener)
  */
 public function boot()
 {
     if ($this->booted) {
         return;
     }
     $debugbar = $this;
     $app = $this->app;
     if ($this->app['config']->get('laravel-debugbar::config.storage.enabled')) {
         $path = $this->app['config']->get('laravel-debugbar::config.storage.path');
         $storage = new FilesystemStorage($this->app['files'], $path);
         $debugbar->setStorage($storage);
     }
     if ($this->shouldCollect('phpinfo', true)) {
         $this->addCollector(new PhpInfoCollector());
     }
     if ($this->shouldCollect('messages', true)) {
         $this->addCollector(new MessagesCollector());
     }
     if ($this->shouldCollect('time', true)) {
         $this->addCollector(new TimeDataCollector());
         $this->app->booted(function () use($debugbar) {
             if (defined('LARAVEL_START')) {
                 $debugbar['time']->addMeasure('Booting', LARAVEL_START, microtime(true));
             }
         });
         //Check if App::before is already called..
         if (version_compare($app::VERSION, '4.1', '>=') && $this->app->isBooted()) {
             $debugbar->startMeasure('application', 'Application');
         } else {
             $this->app->before(function () use($debugbar) {
                 $debugbar->startMeasure('application', 'Application');
             });
         }
         $this->app->after(function () use($debugbar) {
             $debugbar->stopMeasure('application');
             $debugbar->startMeasure('after', 'After application');
         });
     }
     if ($this->shouldCollect('memory', true)) {
         $this->addCollector(new MemoryCollector());
     }
     if ($this->shouldCollect('exceptions', true)) {
         $this->addCollector(new ExceptionsCollector());
     }
     if ($this->shouldCollect('laravel', false)) {
         $this->addCollector(new LaravelCollector());
     }
     if ($this->shouldCollect('default_request', false)) {
         $this->addCollector(new RequestDataCollector());
     }
     if ($this->shouldCollect('events', false) and isset($this->app['events'])) {
         $this->addCollector(new MessagesCollector('events'));
         $dispatcher = $this->app['events'];
         $dispatcher->listen('*', function () use($debugbar, $dispatcher) {
             if (method_exists($dispatcher, 'firing')) {
                 $event = $dispatcher->firing();
             } else {
                 $args = func_get_args();
                 $event = end($args);
             }
             $debugbar['events']->info("Received event: " . $event);
         });
     }
     if ($this->shouldCollect('views', true) and isset($this->app['events'])) {
         $collectData = $this->app['config']->get('laravel-debugbar::config.options.views.data', true);
         $this->addCollector(new ViewCollector($collectData));
         $this->app['events']->listen('composing:*', function ($view) use($debugbar) {
             $debugbar['views']->addView($view);
         });
     }
     if ($this->shouldCollect('route')) {
         if (version_compare($app::VERSION, '4.1', '>=')) {
             $this->addCollector($this->app->make('Barryvdh\\Debugbar\\DataCollector\\IlluminateRouteCollector'));
         } else {
             $this->addCollector($this->app->make('Barryvdh\\Debugbar\\DataCollector\\SymfonyRouteCollector'));
         }
     }
     if ($this->shouldCollect('log', true)) {
         if ($this->hasCollector('messages')) {
             $logger = new MessagesCollector('log');
             $this['messages']->aggregate($logger);
             $this->app['log']->listen(function ($level, $message, $context) use($logger) {
                 if (is_array($message) or is_object($message)) {
                     $message = json_encode($message);
                 }
                 $log = '[' . date('H:i:s') . '] ' . "LOG.{$level}: " . $message . (!empty($context) ? ' ' . json_encode($context) : '');
                 $logger->addMessage($log, $level);
             });
         } else {
             $this->addCollector(new MonologCollector($this->app['log']->getMonolog()));
         }
     }
     if ($this->shouldCollect('db', true) and isset($this->app['db'])) {
         try {
             $pdo = new TraceablePDO($this->app['db']->getPdo());
             $pdoCollector = new PDOCollector($pdo);
             if ($this->app['config']->get('laravel-debugbar::config.options.pdo.with_params')) {
                 $pdoCollector->setRenderSqlWithParams(true, $this->app['config']->get('laravel-debugbar::config.options.pdo.quotation_char'));
             }
             foreach ($this->app['config']->get('laravel-debugbar::config.options.pdo.extra_connections', array()) as $name) {
                 try {
                     $pdo = new TraceablePDO($this->app['db']->connection($name)->getPdo());
                     $pdoCollector->addConnection($pdo, $name);
                 } catch (\Exception $e) {
                     if ($this->hasCollector('exceptions')) {
                         $this['exceptions']->addException($e);
                     } elseif ($this->hasCollector('messages')) {
                         $this['messages']->error($e->getMessage());
                     }
                 }
             }
             $this->addCollector($pdoCollector);
         } catch (\PDOException $e) {
             //Not connection set..
         }
     }
     if ($this->shouldCollect('twig') and isset($this->app['twig'])) {
         $time = isset($this['time']) ? $this['time'] : null;
         $this->app['twig'] = new TraceableTwigEnvironment($this->app['twig'], $time);
         //If we already collect Views, skip the collector (but do add timing)
         if (!$this->hasCollector('views')) {
             $this->addCollector(new TwigCollector($this->app['twig']));
         }
     }
     if ($this->shouldCollect('mail', true)) {
         $mailer = $this->app['mailer']->getSwiftMailer();
         $this->addCollector(new SwiftMailCollector($mailer));
         if ($this->app['config']->get('laravel-debugbar::config.options.mail.full_log') and $this->hasCollector('messages')) {
             $this['messages']->aggregate(new SwiftLogCollector($mailer));
         }
     }
     if ($this->shouldCollect('config', false)) {
         $this->addCollector(new ConfigCollector());
     }
     if ($this->shouldCollect('logs', false)) {
         $file = $this->app['config']->get('laravel-debugbar::config.options.logs.file');
         $this->addCollector(new LogsCollector($file));
     }
     if ($this->shouldCollect('files', false)) {
         $this->addCollector(new FilesCollector());
     }
     if ($this->shouldCollect('auth', false)) {
         $this->addCollector(new IlluminateAuthCollector($this->app['auth']));
     }
     $renderer = $this->getJavascriptRenderer();
     $renderer->setBaseUrl(asset('packages/barryvdh/laravel-debugbar'));
     $renderer->setIncludeVendors($this->app['config']->get('laravel-debugbar::config.include_vendors', true));
     $this->booted = true;
 }
Exemplo n.º 3
0
 /**
  * Register an "after" application filter.
  *
  * @param \Closure|string $callback
  * @return void 
  * @static 
  */
 public static function after($callback)
 {
     \Illuminate\Foundation\Application::after($callback);
 }
Exemplo n.º 4
0
 public function registerListeners()
 {
     // Bind the after event.
     $this->app->after([$this, 'executeAfterHook']);
 }