示例#1
0
 private static function getWhoopsInstance(ServerRequestInterface $request)
 {
     $whoops = new Run();
     if (php_sapi_name() === 'cli') {
         $whoops->pushHandler(new PlainTextHandler());
         return $whoops;
     }
     $format = FormatNegotiator::getPreferredFormat($request);
     switch ($format) {
         case 'json':
             $handler = new JsonResponseHandler();
             $handler->addTraceToOutput(true);
             break;
         case 'html':
             $handler = new PrettyPageHandler();
             break;
         case 'txt':
             $handler = new PlainTextHandler();
             $handler->addTraceToOutput(true);
             break;
         case 'xml':
             $handler = new XmlResponseHandler();
             $handler->addTraceToOutput(true);
             break;
         default:
             if (empty($format)) {
                 $handler = new PrettyPageHandler();
             } else {
                 $handler = new PlainTextHandler();
                 $handler->addTraceToOutput(true);
             }
     }
     $whoops->pushHandler($handler);
     return $whoops;
 }
 public function register()
 {
     if (function_exists('ini_set')) {
         ini_set('display_errors', 0);
     }
     $run = new Run();
     $handler = new ErrorHandler();
     $json_handler = new JsonErrorHandler();
     $cli_handler = new PlainTextHandler();
     $cli_handler->onlyForCommandLine(true);
     $run->pushHandler($handler);
     $run->pushHandler($json_handler);
     $run->pushHandler($cli_handler);
     $run->register();
 }
 public function register()
 {
     if (function_exists('ini_set')) {
         ini_set('display_errors', 0);
     }
     $run = new Run();
     $handler = new ErrorHandler();
     $run->pushHandler($handler);
     $json_handler = new JsonErrorHandler();
     $run->pushHandler($json_handler);
     if (Misc::isCommandLine()) {
         $cli_handler = new PlainTextHandler();
         $cli_handler->addTraceFunctionArgsToOutput(true);
         $cli_handler->addTraceToOutput(true);
         $run->pushHandler($cli_handler);
     }
     $run->register();
 }
 public function register()
 {
     if (function_exists('ini_set')) {
         ini_set('display_errors', 0);
     }
     $run = new Run();
     if (interface_exists('\\Throwable')) {
         $run = new PHP7CompatibleRun($run);
     }
     $handler = new ErrorHandler();
     $run->pushHandler($handler);
     $json_handler = new JsonErrorHandler();
     $cli_handler = new PlainTextHandler();
     $cli_handler->onlyForCommandLine(true);
     $cli_handler->addTraceFunctionArgsToOutput(true);
     $cli_handler->addTraceToOutput(true);
     $run->pushHandler($json_handler);
     $run->pushHandler($cli_handler);
     $run->register();
 }
 /**
  * Initializes the error handler.
  * @return ErrorHandler The initializes error handler
  */
 private function initializeErrorHandler() : ErrorHandler
 {
     $errorHandler = new ErrorHandler();
     $errorHandler->allowQuit(false);
     $errorHandler->writeToOutput(false);
     if ($this->errorLog !== null) {
         $logger = new PlainTextHandler($this->getErrorLogger());
         $logger->loggerOnly(true);
         $errorHandler->pushHandler($logger);
     }
     if ($this->debug) {
         if ($this->jsonRequest) {
             $responseHandler = new JsonResponseHandler();
             $responseHandler->addTraceToOutput(true);
         } else {
             $responseHandler = new PrettyPageHandler();
         }
         $errorHandler->pushHandler($responseHandler);
     }
     return $errorHandler;
 }
 /**
  * @param PlainTextHandler $handler
  *
  * @return void
  */
 public function preparePlainTextHandler(PlainTextHandler $handler)
 {
     $handler->outputOnlyIfCommandLine(false);
 }
示例#7
0
 /**
  * @return int|null
  */
 public function handle()
 {
     if (!$this->handleUnconditionally()) {
         // Check conditions for outputting HTML:
         // @todo: Make this more robust
         if (php_sapi_name() === 'cli') {
             // Help users who have been relying on an internal test value
             // fix their code to the proper method
             if (isset($_ENV['whoops-test'])) {
                 throw new \Exception('Use handleUnconditionally instead of whoops-test' . ' environment variable');
             }
             return Handler::DONE;
         }
     }
     // @todo: Make this more dynamic
     $helper = new TemplateHelper();
     if (class_exists('Symfony\\Component\\VarDumper\\Cloner\\VarCloner')) {
         $cloner = new VarCloner();
         // Only dump object internals if a custom caster exists.
         $cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) {
             $class = $stub->class;
             $classes = [$class => $class] + class_parents($class) + class_implements($class);
             foreach ($classes as $class) {
                 if (isset(AbstractCloner::$defaultCasters[$class])) {
                     return $a;
                 }
             }
             // Remove all internals
             return [];
         }]);
         $helper->setCloner($cloner);
     }
     $templateFile = $this->getResource("views/layout.html.php");
     $cssFile = $this->getResource("css/whoops.base.css");
     $zeptoFile = $this->getResource("js/zepto.min.js");
     $clipboard = $this->getResource("js/clipboard.min.js");
     $jsFile = $this->getResource("js/whoops.base.js");
     if ($this->customCss) {
         $customCssFile = $this->getResource($this->customCss);
     }
     $inspector = $this->getInspector();
     $frames = $inspector->getFrames();
     $code = $inspector->getException()->getCode();
     if ($inspector->getException() instanceof \ErrorException) {
         // ErrorExceptions wrap the php-error types within the "severity" property
         $code = Misc::translateErrorCode($inspector->getException()->getSeverity());
     }
     // Detect frames that belong to the application.
     if ($this->applicationPaths) {
         /* @var \Whoops\Exception\Frame $frame */
         foreach ($frames as $frame) {
             foreach ($this->applicationPaths as $path) {
                 if (substr($frame->getFile(), 0, strlen($path)) === $path) {
                     $frame->setApplication(true);
                     break;
                 }
             }
         }
     }
     // List of variables that will be passed to the layout template.
     $vars = ["page_title" => $this->getPageTitle(), "stylesheet" => file_get_contents($cssFile), "zepto" => file_get_contents($zeptoFile), "clipboard" => file_get_contents($clipboard), "javascript" => file_get_contents($jsFile), "header" => $this->getResource("views/header.html.php"), "header_outer" => $this->getResource("views/header_outer.html.php"), "frame_list" => $this->getResource("views/frame_list.html.php"), "frames_description" => $this->getResource("views/frames_description.html.php"), "frames_container" => $this->getResource("views/frames_container.html.php"), "panel_details" => $this->getResource("views/panel_details.html.php"), "panel_details_outer" => $this->getResource("views/panel_details_outer.html.php"), "panel_left" => $this->getResource("views/panel_left.html.php"), "panel_left_outer" => $this->getResource("views/panel_left_outer.html.php"), "frame_code" => $this->getResource("views/frame_code.html.php"), "env_details" => $this->getResource("views/env_details.html.php"), "title" => $this->getPageTitle(), "name" => explode("\\", $inspector->getExceptionName()), "message" => $inspector->getException()->getMessage(), "code" => $code, "plain_exception" => Formatter::formatExceptionPlain($inspector), "frames" => $frames, "has_frames" => !!count($frames), "handler" => $this, "handlers" => $this->getRun()->getHandlers(), "active_frames_tab" => count($frames) && $frames->offsetGet(0)->isApplication() ? 'application' : 'all', "has_frames_tabs" => $this->getApplicationPaths(), "tables" => ["GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : [], "Server/Request Data" => $_SERVER, "Environment Variables" => $_ENV]];
     if (isset($customCssFile)) {
         $vars["stylesheet"] .= file_get_contents($customCssFile);
     }
     // Add extra entries list of data tables:
     // @todo: Consolidate addDataTable and addDataTableCallback
     $extraTables = array_map(function ($table) use($inspector) {
         return $table instanceof \Closure ? $table($inspector) : $table;
     }, $this->getDataTables());
     $vars["tables"] = array_merge($extraTables, $vars["tables"]);
     if (\Whoops\Util\Misc::canSendHeaders()) {
         header('Content-Type: text/html');
     }
     $plainTextHandler = new PlainTextHandler();
     $plainTextHandler->setException($this->getException());
     $plainTextHandler->setInspector($this->getInspector());
     $vars["preface"] = "<!--\n\n\n" . $plainTextHandler->generateResponse() . "\n\n\n\n\n\n\n\n\n\n\n-->";
     $helper->setVariables($vars);
     $helper->render($templateFile);
     return Handler::QUIT;
 }
示例#8
0
 /**
  * @param PlainTextHandler $handler
  *
  * @return void
  */
 public function preparePlainTextHandler(PlainTextHandler $handler)
 {
     $handler->addTraceToOutput(true);
 }