/** * Dumps a given value with optional name and backtrace if dump is allowed for current user state * * Usage: * <code> * Oops_Debug::Dump($var); * Oops_Debug::Dump($thatvar,"That var"); * Oops_Debug::Dump($var,"Some label",true); //will output complete backtrace * </code> * * @param mixed Value to dump * @param string Label * @param bool Output full backtrace or only the last element * @return void */ public static function Dump($value, $name = null, $fullTrace = false) { if (!Oops_Debug::allow()) { return; } echo '<div class="oops-debug" style="border: 1px solid #FF0000">'; if (!is_null($name)) { echo "<b>" . $name . "</b>="; } Oops_Debug::print_r_dhtml($value); $data = debug_backtrace(); $count = count($data); $start = $count == 1 ? 0 : 1; $start = 0; echo '<div style="border: 1px solid #00FF00">'; for ($i = $start; $i < $count; $i++) { $obj = $data[$i]; echo '<span style="font: Courier New, Courier, mono; color: #0000FF; font-size: 14px;">'; echo "{$obj['class']}->{$obj['function']}</span>::<b>{$obj['line']}</b><small>({$obj['file']})</small><br>"; if (!$fullTrace) { break; } } echo "</div>\n</div>"; }
/** * Run the application and output the response * * @param Oops_Server_Request $request * Request to dispatch * @return void */ public function Run($request = null) { // @todo skip hander and use error log, or use static handler that will // log errors? $this->_errorHandler = new Oops_Error_Handler(); try { if (!is_object($request)) { $this->_request = new Oops_Server_Request_Http(); $this->_response = new Oops_Server_Response_Http(); } else { $this->_request = $request; $this->_response = new Oops_Server_Response(); } $this->_parseRequest(); $this->_initView(); $this->_routeRequest(); // @todo try to find controller action, then do everything else $this->_initController(); $data = $this->_controller_instance->Run(); // @todo Let the view handler use getRequest and getResponse as it // need it $this->_view->In($data); $this->_view->Set('controller', $this->_router->controller); $this->_view->Set('uri', $this->_request->getUri()); $this->_view->Set('ext', $this->_extension); $this->_view->Set('action', $this->_action); $this->_view->Set('uri_parts', $this->_uri_parts); $this->_response->setHeader("Content-type", $this->_view->getContentType()); $this->_response->setBody($this->_view->Out()); } catch (Oops_Server_Exception $e) { // Here we catch cases where response code was set by router or // controller (302, 301, 404 еtс) switch ($e->getCode()) { case OOPS_SERVER_EXCEPTION_RESPONSE_READY: // // init response code handler here $responseCodeHandler = $this->loadResponseCodeHandler(); $responseCodeHandler->handle($this->_response); break; default: // @todo refactor unknown exceptions catching to log and 500 throw $e; } } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } // @todo refactor error logging etc if ((string) $this->_config->oops->errors2Headers && Oops_Debug::allow()) { $this->_response->reportErrors($this->_errorHandler); } if ((string) $this->_config->oops->errorlog->enabled) { Oops_Log_Error::report($this->_errorHandler, $this->_config->oops->errorlog->path); } restore_error_handler(); return $this->_response; }