/**
  * Instantiate Whoops with the correct handlers.
  */
 public function init()
 {
     parent::init();
     require 'YiiWhoopsRunner.php';
     $this->whoops = new YiiWhoopsRunner();
     if (Yii::app()->request->isAjaxRequest) {
         $this->whoops->pushHandler(new JsonResponseHandler());
     } else {
         $page_handler = new PrettyPageHandler();
         if (isset($this->pageTitle)) {
             $page_handler->setPageTitle($this->pageTitle);
         }
         if (isset($this->editor)) {
             $editor = $this->editor;
             switch ($editor) {
                 case 'sublime':
                 case 'emacs':
                 case 'textmate':
                 case 'macvim':
                 case 'xdebug':
                     $page_handler->setEditor($editor);
                     break;
                 default:
                     $page_handler->setEditor(function ($file, $line) use($editor) {
                         return strtr($editor, array('{file}' => $file, '{line}' => $line));
                     });
                     break;
             }
         }
         $this->whoops->pushHandler($page_handler);
     }
 }
 /**
  * Instantiate Whoops with the correct handlers.
  */
 public function __construct()
 {
     require 'YiiWhoopsRunner.php';
     $this->whoops = new YiiWhoopsRunner();
     if (Yii::app()->request->isAjaxRequest) {
         $this->whoops->pushHandler(new JsonResponseHandler());
     } else {
         $contentType = '';
         foreach (headers_list() as $header) {
             list($key, $value) = explode(':', $header);
             $value = ltrim($value, ' ');
             if (strtolower($key) === 'content-type') {
                 // Split encoding if exists
                 $contentType = explode(";", strtolower($value));
                 $contentType = current($contentType);
                 break;
             }
         }
         if ($contentType && strpos($contentType, 'json')) {
             $this->whoops->pushHandler(new JsonResponseHandler());
         } else {
             $page_handler = new PrettyPageHandler();
             if ($this->pageTitle) {
                 $page_handler->setPageTitle($this->pageTitle);
             }
             $reordered_tables = array('Request information' => static::createRequestTable(), "GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : array(), "Environment Variables" => $_ENV, "Server/Request Data" => $_SERVER);
             foreach ($reordered_tables as $label => $data) {
                 $page_handler->addDataTable($label, $data);
             }
             $this->whoops->pushHandler($page_handler);
         }
     }
 }