/** * Render the profiler. Output is added to the bottom of the page by default. * * @param boolean return the output if YES * @return void|string */ public function render($return = NO) { $start = microtime(YES); $get = isset($_GET['profiler']) ? explode(',', $_GET['profiler']) : array(); $this->show = empty($get) ? Eight::config('profiler.show') : $get; Event::run('profiler.run', $this); $styles = ''; foreach ($this->profiles as $profile) { $styles .= $profile->styles(); } // Don't display if there's no profiles if (empty($this->profiles)) { return; } // Load the profiler view $data = array('profiles' => $this->profiles, 'styles' => $styles, 'execution_time' => microtime(YES) - $start); $view = new View('profiler/profiler', $data); // Return rendered view if $return is YES if ($return == YES) { return $view->render(); } // Add profiler data to the output if (stripos(Eight::$output, '</body>') !== NO) { // Closing body tag was found, insert the profiler data before it Eight::$output = str_ireplace('</body>', $view->render() . '</body>', Eight::$output); } else { // Append the profiler data to the output Eight::$output .= $view->render(); } }
/** * Prevent any output from being displayed. Executed during system.display. * * @return void */ public static function prevent_output() { Eight::$output = ''; }
/** * Eight output handler. * * @param string current output buffer * @return string */ public static function output_buffer($output) { if (!Event::has_run('system.send_headers')) { // Run the send_headers event, specifically for cookies being set Event::run('system.send_headers'); } // Set final output self::$output = $output; // Look for errors in the output buffer if (!self::$configuration['core']['display_errors'] && self::$configuration['core']['catch_all_errors']) { if (preg_match('#<phperror>.*</phperror>#is', self::$output, $matches)) { // We only care about the first error $match = $matches[0]; // Pull some info out of the error preg_match('#error:(.*)\\ in\\ (.*)\\ on\\ line ([0-9]+)#i', strip_tags($match), $matches); $error = new Eight_Exception_PHP(E_ERROR, trim($matches[1]), trim($matches[2]), trim($matches[3])); // Log the error self::log('error', Eight_Exception_PHP::text($error)); self::log_save(); // Show the pretty error page self::$output = file_get_contents(self::find_file('views', 'eight/error_disabled', TRUE)); } } // Set and return the final output return self::$output; }
/** * Eight output handler. * * @param string current output buffer * @return string */ public static function output_buffer($output) { if (!Event::has_run('system.send_headers')) { // Run the send_headers event, specifically for cookies being set Event::run('system.send_headers'); } // Set final output self::$output = $output; // Set and return the final output return self::$output; }