Esempio n. 1
0
 private function logQuery($method, $query, array $params = null, $isSelect)
 {
     /** @var \PDOStatement $st */
     $st = null;
     $showQuery = function ($dur = null) use($query, $params, &$st, $isSelect) {
         $query = trim($query);
         DebugConsole::logger('database')->inspect('<#section|SQL QUERY>', $this->highlightQuery($query, self::$SQL_KEYWORDS, 'identifier'));
         if (!empty($params)) {
             DebugConsole::logger('database')->write("<#header>Parameters</#header>")->inspect($params);
         }
         DebugConsole::logger('database')->write(sprintf("<#footer>Query took <b>%s</b> milliseconds" . ($isSelect ? '' : ' and affected <b>%d</b> records') . "</#footer>", $dur * 1000, $st ? $st->rowCount() : 0));
         DebugConsole::logger('database')->write('</#section>');
     };
     $start = microtime(true);
     try {
         $st = $this->decorated->{$method}($query, $params);
     } catch (PDOException $e) {
         $showQuery();
         DebugConsole::logger('database')->write('<#footer><#alert>Query failed!</#alert></#footer>');
         DebugConsole::throwErrorWithLog($e);
     }
     $end = microtime(true);
     $dur = round($end - $start, 4);
     $showQuery($dur);
     return $st;
 }
 protected function callHandler(callable $handler, ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     /** Router $this */
     $this->routingLogger->writef("<#row>Call %s</#row>", Debug::getType($handler));
     DebugConsole::logger('request')->setRequest($request);
     if ($request && $request != $this->currentRequestMutator->get()) {
         $this->logRequest($request, sprintf('with another %s object:', Debug::getType($request)));
         //      $this->currentRequestMutator->set ($request); // DO NOT DO THIS HERE; IT WILL BE DONE ON THE PARENT.
         self::$currentRequestSize = $request->getBody()->getSize();
     }
     if ($response && $response != self::$currentResponse) {
         $this->logRequest($request, sprintf('with a new %s object:', Debug::getType($response)));
         self::$currentResponse = $response;
         self::$currentResponseSize = $response->getBody()->getSize();
     }
     $response = parent::callHandler($handler, $request, $response, $next);
     $this->routingLogger->writef("<#row>Return from %s</#row>", Debug::getType($handler));
     if ($response !== self::$currentResponse) {
         $this->logResponse($response, sprintf('with a new %s object:', Debug::getType($response)));
         self::$currentResponse = $response;
         self::$currentResponseSize = $response->getBody()->getSize();
     } else {
         $newSize = $response->getBody()->getSize();
         if ($newSize != self::$currentResponseSize) {
             $this->logResponse($response, sprintf('with a modified %s body:', Debug::getType($response)));
             self::$currentResponseSize = $newSize;
         }
     }
     return $response;
 }
 /**
  * Writes the record down to the log of the implementing handler
  *
  * @param  array $record
  * @return void
  */
 protected function write(array $record)
 {
     if (DebugConsole::$initialized) {
         $channel = $record['channel'];
         $loggerId = DebugConsole::hasLogger($channel) ? $channel : DebugConsole::$settings->defaultLoggerId;
         $logger = DebugConsole::logger($loggerId);
         $logger->log($record['level'], $record['message'], $record['context']);
     }
 }
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $mode = $this->settings->selectionMode();
     $this->locale->selectionMode($mode);
     if ($mode == 'session') {
         $lang = $this->session->getLang() ?: $this->locale->defaultLang();
         $this->locale->locale($lang);
         $this->session->setLang($lang);
     }
     if ($this->webConsole) {
         DebugConsole::logger('config')->inspect($this->locale);
     }
     return $next();
 }
 static function startUp(KernelInterface $kernel, ModuleInfo $moduleInfo)
 {
     $kernel->onConfigure(function (LoggerInterface $logger, $webConsole) {
         if ($webConsole) {
             DebugConsole::registerPanel('request', new PSR7RequestLogger('Request', 'fa fa-paper-plane'));
             DebugConsole::registerPanel('response', new PSR7ResponseLogger('Response', 'fa fa-file'));
             DebugConsole::registerPanel('routes', new ConsoleLogger('Routing', 'fa fa-location-arrow'));
             DebugConsole::registerPanel('navigation', new ConsoleLogger('Navigation', 'fa fa-compass big'));
             DebugConsole::registerPanel('config', new ConsoleLogger('Configuration', 'fa fa-cogs'));
             DebugConsole::registerPanel('session', new ConsoleLogger('Session', 'fa fa-user'));
             DebugConsole::registerPanel('database', new ConsoleLogger('Database', 'fa fa-database'));
             DebugConsole::registerLogger('trace', new ConsoleLogger('Trace', 'fa fa-clock-o big'));
             //    DebugConsole::registerPanel ('exceptions', new ConsoleLogger ('Exceptions', 'fa fa-bug'));
             // Writing to the logger also writes to the Inspector panel.
             if ($logger instanceof Logger) {
                 $logger->pushHandler(new WebConsoleMonologHandler(env('DEBUG_LEVEL') ?: Logger::DEBUG));
             }
         }
     });
 }
 /**
  * @param string $rootDir
  */
 private function setupDebugging($rootDir)
 {
     set_exception_handler([$this, 'exceptionHandler']);
     $devEnv = env('DEV');
     $this->injector->defineParam('devEnv', $devEnv);
     $webConsole = env('CONSOLE');
     $this->injector->defineParam('webConsole', $webConsole);
     ErrorConsole::init($devEnv, $rootDir);
     ErrorConsole::setAppName($this->kernelSettings->appName);
     // Note: the editorUrl can't be set yet. See: WebServer.
     $settings = new DebugConsoleSettings();
     $settings->defaultPanelTitle = 'Inspector';
     $settings->defaultPanelIcon = 'fa fa-search';
     DebugConsole::init($devEnv, $settings);
     // Temporarily set framework path mapping here for errors thrown during modules loading.
     ErrorConsole::setPathsMap($this->kernelSettings->getMainPathMap());
 }
 function _log()
 {
     return DebugConsole::defaultLogger();
 }
Esempio n. 8
0
 function inspectOnConsole($deep = true)
 {
     DebugConsole::defaultLogger()->write($this->inspect($deep));
 }
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if (!$this->webConsole) {
         // In case the middleware was registered.
         return $next();
     }
     //------------------------------------------------------------------
     /** @var ResponseInterface $response */
     $response = $next();
     $contentType = $response->getHeaderLine('Content-Type');
     $status = $response->getStatusCode();
     if ($status >= 300 && $status < 400 || $contentType && $contentType != 'text/html') {
         return $response;
     }
     $response->getBody()->rewind();
     //------------------
     // Logging panel
     //------------------
     if (extension_loaded('xdebug')) {
         DebugConsole::defaultLogger()->write('<#alert><b>Warning:</b> When running with Xdebug enabled, the framework\'s performance is severely degraded, especially on debug mode.</#alert>' . '<p class=__comment>Refer to the framework\'s documentation for more information.</p>');
     }
     //------------------
     // Request panel
     //------------------
     $log = DebugConsole::logger('request');
     if (!$log->hasRequest()) {
         $log->setRequest($request);
     }
     //------------------
     // Response panel
     //------------------
     DebugConsole::logger('response')->setResponse($response);
     //------------------
     // Routing panel
     //------------------
     $router = $this->injector->make(ApplicationRouterInterface::class);
     $handlers = $router->__debugInfo()['handlers'];
     $rootR = $handlers ? implode('', map($handlers, function ($r) {
         return sprintf('<#row><#type>%s</#type></#row>', is_string($r) ? $r : typeOf($r));
     })) : '<#i><i>empty</i></#i>';
     $logger = $this->injector->make(RoutingLogger::class);
     $log = $logger->getContent();
     DebugConsole::logger('routes')->write("<#section|REGISTERED ROUTERS>{$rootR}</#section>" . "<#section|APPLICATION MIDDLEWARE STACK &nbsp;┊&nbsp; RUN HISTORY>")->write($log)->write("<#row>Return from ")->typeName($this)->write("</#row>")->write("<#row><i>(log entries from this point on can't be displayed)</i></#row>")->write("</#indent>")->write("<#row>Exit stack 1</#row>")->write("<#row>End of routing log</#row>")->write("</#section>");
     //------------------
     // Navigation panel
     //------------------
     if ($this->injector->provides(NavigationInterface::class)) {
         try {
             /** @var NavigationInterface $navigation */
             $navigation = $this->injector->make(NavigationInterface::class);
             DebugConsole::logger('navigation')->withFilter(function ($k, $v, $o) use($navigation) {
                 if ($k === 'parent' || $k === 'request') {
                     return '...';
                 }
                 if ($k === 'IDs' && $o != $navigation->rootLink()) {
                     return '...';
                 }
                 return true;
             }, $navigation);
         } catch (\Exception $e) {
         }
     }
     //------------------
     // Config. panel
     //------------------
     DebugConsole::logger('config')->inspect($this->kernelSettings);
     //------------------
     // Session panel
     //------------------
     if ($this->injector->provides(SessionInterface::class)) {
         DebugConsole::logger('session')->write('<button type="button" class="__btn __btn-default" style="position:absolute;right:5px;top:5px" onclick="location.href=\'logout\'">Log out</button>')->inspect($this->injector->make(SessionInterface::class));
     }
     //------------------
     // Tracing panel
     //------------------
     $trace = DebugConsole::logger('trace');
     if ($trace->hasContent()) {
         DebugConsole::registerPanel('trace', $trace);
     }
     return DebugConsole::outputContentViaResponse($request, $response, true);
 }
 protected function afterRender()
 {
     parent::afterRender();
     //----------------------------------------------------------------------------------------
     // View Model panel
     // (MUST run before the DOM panel to capture the data-binding stack at its current state)
     //----------------------------------------------------------------------------------------
     DebugConsole::registerPanel('view', new ConsoleLogger('View', 'fa fa-eye'));
     $VMFilter = function ($k, $v, $o) {
         if ($v instanceof DocumentContext || $v instanceof Component || $k === 'parent' || $k === 'model') {
             return '...';
         }
         return true;
     };
     $expMap = Expression::$inspectionMap;
     ksort($expMap);
     DebugConsole::logger('view')->withFilter($VMFilter, $this->context)->write('<#section|Compiled expressions>')->inspect($expMap)->write('</#section>');
     //------------
     // Model panel
     //------------
     DebugConsole::registerPanel('model', new ConsoleLogger('Model', 'fa fa-table'));
     $shadowDOM = $this->getShadowDOM();
     if ($shadowDOM) {
         $VMFilter = function ($k, $v, $o) {
             if ($v instanceof KernelSettings || $v instanceof NavigationInterface || $v instanceof NavigationLinkInterface || $v instanceof SessionInterface || $v instanceof ServerRequestInterface || $v instanceof DocumentContext || $v instanceof Component) {
                 return '...';
             }
             return true;
         };
         $binder = $shadowDOM->getDataBinder();
         DebugConsole::logger('model')->write('<#i>PAGE DATA BINDER: ' . Debug::getType($binder) . "</#i>")->write("<#section|PAGE VIEW MODEL>")->withFilter($VMFilter, $binder->getViewModel())->write("</#section>");
     }
     //-----------
     // DOM panel
     //-----------
     if ($this->matisseSettings->inspectDOM()) {
         DebugConsole::registerPanel('DOM', new ConsoleLogger('Server-side DOM', 'fa fa-sitemap'));
         $insp = $this->inspect(true);
         DebugConsole::logger('DOM')->write($insp);
     }
 }