Example #1
0
 /**
  * This will finish buffering, and output the page.
  * It also appends the magic JS onto the beginning of the page,
  * if enabled, to allow working with Ajax.
  * 
  * Note that if PHP Error has been disabled in the php.ini file,
  * or through some other option, such as running from the command line,
  * then this will do nothing (as no buffering will take place).
  */
 public function endBuffer()
 {
     if ($this->isBufferSetup && self::isCLI() == false) {
         if ($this->isDisplayingErrors() && !$this->isAjax && $this->catchAjaxErrors && (!$this->htmlOnly || !ErrorHandler::isNonPHPRequest()) && !ErrorHandler::isBinaryRequest()) {
             $content = ob_get_contents();
             if (ob_get_level()) {
                 ob_clean();
             }
             $js = $this->getJSInjection();
             // attemp to inject the script into the HTML, after the doctype
             $matches = array();
             preg_match(ErrorHandler::REGEX_DOCTYPE, $content, $matches);
             if ($matches) {
                 $doctype = $matches[0];
                 $content = preg_replace(ErrorHandler::REGEX_DOCTYPE, "{$doctype} {$js}", $content);
             } else {
                 echo $js;
             }
             echo $content;
         }
         if (ob_get_level()) {
             ob_end_flush();
         }
     }
 }