/** * Generate a Response for the 404 Exception. * * The user should be shown a nice 404 page. * * @return Response */ public function get_response() { Kohana_Exception::log($this); $response = Request::factory(Route::get('default')->uri(array('controller' => 'Errors', 'action' => '404')))->execute(); $response->status(404); return $response; }
/** * Inline exception handler, displays the error message, source of the * exception, and the stack trace of the error. * * Should this display a stack trace? It's useful. * * @uses Kohana_Exception::text * @param Exception $e * @return boolean */ public static function handler(Exception $e) { try { // Log the exception Kohana_Exception::log($e); if ($e instanceof Minion_Exception) { echo $e->format_for_cli(); } else { echo Kohana_Exception::text($e); } $exit_code = $e->getCode(); // Never exit "0" after an exception. if ($exit_code == 0) { $exit_code = 1; } exit($exit_code); } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo Kohana_Exception::text($e), "\n"; // Exit with an error status exit(1); } }
public static function response(Exception $e) { // get the response $response = parent::response($e); // Log the Exception, Kohana_Exception::log($e); if (Kohana::DEVELOPMENT !== Kohana::$environment) { try { // fire error subrequest // directly output result echo Request::factory(Route::get('error')->uri(array('controller' => 'error', 'action' => 'view')))->post('exception', $e)->execute()->send_headers()->body(); exit; } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Exit with an error status exit; } } // end all output buffering $ob = ob_get_level(); for ($i = 0; $i < $ob; $i++) { ob_end_clean(); } // return the response as usual return $response; }
/** * @param Exception $e */ protected static function log(Exception $e) { $logLevel = self::config('cache.log.exceptions', static::$logExceptions); if (FALSE !== $logLevel) { Kohana_Exception::log($e, $logLevel); } }
public function get_response() { Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { return parent::get_response(); } else { $response = Response::factory()->status(401)->headers('Location', URL::site('/')); return $response; } }
/** * Generates a Response for all Exceptions without a specific override * * @return Response */ public function get_response() { // Log the exception Kohana_Exception::log($this); $response = Response::factory(); $view = Swiftriver::get_base_error_view(); $view->content = View::factory('pages/errors/404')->set('page', $this->request()->uri()); $response->body($view->render()); return $response; }
public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); $params = array('code' => $this->getCode(), 'message' => rawurlencode($this->getMessage()), 'response' => NULL, 'errors' => $this->_errors); try { return json_encode($params); } catch (Exception $e) { return parent::get_response(); } }
public function get_response() { Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { return parent::get_response(); } else { $view = View::factory('templates/errors/default'); $view->set('title', "400 Bad Request"); $view->set('message', "{$this->getMessage()}"); $response = Response::factory()->status(400)->body($view->render()); return $response; } }
/** * Generate a Response for all Exceptions without a more specific override * * The user should see a nice error page, however, if we are in development * mode we should show the normal Kohana error page. * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { // Show the normal Kohana error page. return parent::get_response(); } else { $response = Request::factory(Route::get('default')->uri(array('controller' => 'Errors', 'action' => 'index')))->execute(); $response->status($this->getCode()); return $response; } }
public function get_response() { Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { return parent::get_response(); } else { $view = View::factory('templates/errors/default'); $view->set('title', 'Произошла ошибка'); $view->set('message', $this->getMessage()); $response = Response::factory()->status($this->getCode())->body($view->render()); Model_Methods::telegram_send_error($this->getMessage()); return $response; } }
/** * Generate a Response for all Exceptions without a more specific override * * The user should see a nice error page, however, if we are in development * mode we should show the normal Kohana error page. * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { // Show the normal Kohana error page. return parent::get_response(); } else { // Generate a nicer looking "Oops" page. $view = View::factory('error/default'); $response = Response::factory()->status($this->getCode())->body($view->render()); return $response; } }
/** * Generate a Response for all Exceptions without a more specific override * * The user should see a nice error page, however, if we are in development * mode we should show the normal Kohana error page. * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); $params = array('code' => 500, 'message' => rawurlencode($this->getMessage()), 'response' => NULL); if ($this instanceof HTTP_Exception) { $params['code'] = $this->getCode(); } try { return json_encode($params); } catch (Exception $e) { return parent::get_response(); } }
/** * Generate a Response for all Exceptions without a more specific override * The user should see a nice error page, however, if we are in development * mode we should show the normal Kohana error page. * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { // Show the normal Kohana error page. return parent::get_response(); } else { $attributes = ['action' => 500]; // Get error code as action name if ($this instanceof HTTP_Exception) { $attributes['action'] = $this->getCode(); $attributes['message'] = $this->getMessage(); } // Execute the query, addressed to the router for error handling return Request::factory(Route::get('error')->uri($attributes))->execute(); } }
public static function handler($e) { try { Kohana_Exception::log($e); if (PHP_SAPI == 'cli') { $response = Kohana_Exception::text($e); } else { $response = Kohana_Exception::response($e); } echo $response; exit(1); } catch (Exception $e) { ob_get_level() and ob_clean(); header('Content-Type: text/plain; charset=utf-8', TRUE, 500); echo Kohana_Exception::text($e); exit(1); } }
/** * Run CSRF check and load frontend assets. */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { // Show the normal Kohana error page. return parent::get_response(); } $response = Response::factory(); $assets = Kohana::$config->load('assets.global'); $this->_load_assets($assets); $view = new View_Error(); $view->title = $this->getCode(); $view->message = $this->getMessage(); $renderer = Kostache_Layout::factory(); $response->body($renderer->render($view)); return $response; }
/** * Generate a Response for all Exceptions without a more specific override * * The user should see a nice error page, however, if we are in development * mode we should show the normal Kohana error page. * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); if (Config::get('site', 'debug') == Config::YES) { // Show the normal Kohana error page. return parent::get_response(); } else { $params = array('code' => 500, 'message' => rawurlencode($this->getMessage())); if ($this instanceof HTTP_Exception) { $params['code'] = $this->getCode(); } try { $request = Request::factory(Route::get('error')->uri($params), array(), FALSE)->execute()->send_headers(TRUE)->body(); return Response::factory()->status($this->getCode())->body($request); } catch (Exception $e) { return parent::get_response(); } } }
/** * Generate a Response for the 500 Exception. * * Internal * The user should be shown a nice 500 page. * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { // Show the normal Kohana error page. return parent::get_response(); } else { // Get tpl directory $front_tpl_dir = Cms_Helper::settings('front_tpl_dir'); // Get file $content_file = Tpl::get_file($this->code, $front_tpl_dir . '/error'); // Set variable and render $content = Tpl::factory($content_file)->set('code', $this->getCode())->set('message', $this->getMessage())->set('request_url', URL::site(Request::current()->url(), "http"))->render(); // Factory response $response = Response::factory(); $response->body($content); return $response; } }
/** * Exception handler, logs the exception and generates a Response object * for display. * * @uses Kohana_Exception::response * * @param Exception $e * * @return Response */ public static function _handler(Exception $e) { try { // Log the exception Kohana_Exception::log($e); // Generate the response $response = Kohana_Exception::response($e); return $response; } catch (Exception $e) { /** * Things are going *really* badly for us, We now have no choice * but to bail. Hard. */ // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Set the Status code to 500, and Content-Type to text/plain. header('Content-Type: text/plain; charset=' . Kohana::$charset, true, 500); echo Kohana_Exception::text($e); exit(1); } }
/** * Generate a Response for all Exceptions without a more specific override * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); // View $view = View::factory('error'); $view->exception = $this; $view->previous = $this->getPrevious(); // Page $page = View::factory('template'); $page->controller = 'error'; $page->action = 'error'; $page->table = ''; $page->tables = array(); $page->database = ''; $page->databases = array(); $page->content = $view->render(); // Response $response = Response::factory()->status($this->getCode())->body($page->render()); return $response; }
/** * Get a Response object representing the exception * * @uses Kohana_Exception::text * @param Exception $e * @return Response */ public static function response(Exception $e) { // Log the exception Kohana_Exception::log($e); try { // Get the exception information $code = $e->getCode(); $message = $e->getMessage(); if (!headers_sent()) { // Make sure the proper http header is sent $http_header_status = $e instanceof HTTP_Exception ? $code : 500; } if ($e instanceof ErrorException && isset(Kohana_Exception::$php_errors[$code])) { // Use the human-readable error name $code = Kohana_Exception::$php_errors[$code]; } // Prepare the response object. $response = Response::factory(); // Set the response status $response->status($e instanceof HTTP_Exception ? $e->getCode() : 500); // Set the response headers $response->headers('Content-Type', 'application/api-problem+json; charset=' . Kohana::$charset); if (empty($message)) { $message = Arr::get(Response::$messages, $response->status()); } // Set the response body $response->body($message); } catch (Exception $e) { /** * Things are going badly for us, Lets try to keep things under control by * generating a simpler response object. */ $response = Response::factory(); $response->status(500); $response->headers('Content-Type', 'text/plain'); $response->body(Kohana_Exception::text($e)); } return $response; }
public function action_index() { $this->template->content = View::factory('deals/index')->bind('products', $products)->bind('numproducts', $numproducts)->bind('filter_name', $merchant); $merchant = ''; $results_per_page = 0; // get url params if ($this->request->query('merchant') !== null && $this->request->query('results_per_page') !== null) { $merchant = $this->request->query('merchant'); $results_per_page = $this->request->query('results_per_page'); } $key = Kohana::$config->load('rest')->get('hotukdeals')['api_key']; $fmt = Kohana::$config->load('rest')->get('hotukdeals')['api_search_url_fmt']; $url = sprintf($fmt, $key, $merchant, $results_per_page); $cache_life = Kohana::$config->load('rest')->get('hotukdeals')['cache_life']; $cache_key = 'products:' . $url; // retrieve cached data from RESTful service try { if (($products = Kohana::cache($cache_key, NULL, $cache_life)) === NULL) { $objects = Helper::factory('REST')->url($url)->as_object()->execute(); $products = $objects->deals->items; foreach ($products as $product) { $product->display_page_url = $this->_get_product_display_page($product->deal_image); } $products = $this->_remove_expired_products($products); $products = $this->_order_by_temperature($products); // store retrieved products to cache Kohana::cache($cache_key, $products, $cache_life); } $numproducts = count($products); } catch (ErrorException $e) { //clear cache Kohana::cache($cache_key, NULL, 0); if (is_object(Kohana::$log)) { Kohana_Exception::log($e); } $this->template->content = View::factory('deals/error'); } }
/** * Generate a Response for all Exceptions without a more specific override * * The user should see a nice error page, however, if we are in development * mode we should show the normal Kohana error page. * * @return Response */ public function get_response() { // Lets log the Exception, Just in case it's important! Kohana_Exception::log($this); if (Kohana::$environment >= Kohana::DEVELOPMENT) { // Show the normal Kohana error page. return parent::get_response(); } else { $view = View::factory('errors/default'); $view->error_code = $this->getCode(); $view->message = $this->getMessage(); $template = View::factory('blank'); $system_settings = ORM::factory('Systemsetting')->where('name', 'IN', array('language'))->find_all()->as_array('name', 'value'); $template->title = $this->getMessage(); $template->meta_description = $this->getMessage(); $template->meta_keywords = ""; $template->head_style = ""; $template->html_lang = $system_settings['language']; $template->content = $view->render(); $response = Response::factory()->status($this->getCode())->body($template->render()); return $response; } }
public static function handler(Exception $e) { try { // Log the exception Kohana_Exception::log($e); // Let's try and load an error View $class = get_class($e); if ($class == 'HTTP_Exception_404') { $view = View::factory('errors/404'); $view->set('error_code', 404); } else { $view = View::factory('errors/general'); $view->set('error_code', $e->getCode()); // alternatively use $e->getCode() $view->set('error_message', $e->getMessage()); // alternatively use $e->getMessage(); } var_dump(1); // Let's render the output and send it to the browser $response = $view->render(); echo $response; } catch (Exception $e) { /** * Things are going *really* badly for us, We now have no choice * but to bail. Hard. */ // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Set the Status code to 500, and Content-Type to text/plain. header('Content-Type: text/plain; charset=' . Kohana::$charset, TRUE, 500); // This will output the Exceptiones error message // You may want to display something else echo $e->getMessage(); exit(1); } }
Kohana::modules(array('database' => MODPATH . 'database', 'helper' => MODPATH . 'helper', 'image' => MODPATH . 'image', 'imagefly' => MODPATH . 'imagefly', 'captcha' => MODPATH . 'captcha', 'cache' => MODPATH . 'cache', 'devtools' => MODPATH . 'devtools', 'logreader' => MODPATH . 'logreader', 'myadmin' => MODPATH . 'myadmin', 'media' => MODPATH . 'media', 'weixin' => MODPATH . 'weixin', 'auth' => MODPATH . 'auth', 'oauth2' => MODPATH . 'oauth2', 'payment' => MODPATH . 'payment')); Kohana::$log->attach(new Log_File(APPPATH . 'logs')); Route::set('list_pinyin_mult', '(<city_pinyin>/)ershouche(/<brand_pinyin>(-<series_pinyin>))(/(p<price_f>-<price_t>)(y<year_f>-<year_t>)(m<mile>)(s<sort_f>-<sort_d>))(/p<page>)(.<format>)', array('city_pinyin' => '[a-z]+', 'brand_pinyin' => '[a-z]+', 'series_pinyin' => '([a-z]+([a-z0-9]+)?){2,}', 'price_f' => '(\\d+)', 'price_t' => '(\\d+)', 'year_f' => '(\\d+)', 'year_t' => '(\\d+)', 'mile' => '(\\d+(-\\d+)*)', 'sort_f' => '(p|y|m)', 'sort_d' => '(a|d)', 'page' => '(\\d+)', 'format' => '(html|htm)'))->defaults(array('controller' => 'list')); Route::set('list_pinyin', '(<city_pinyin>/)ershouche(/<brand_pinyin>(-<series_pinyin>))(/(p<price_f>-<price_t>)(y<year_f>-<year_t>)(m<mile_f>-<mile_t>)(s<sort_f>-<sort_d>))(/p<page>)(.<format>)', array('city_pinyin' => '[a-z]+', 'brand_pinyin' => '[a-z]+', 'series_pinyin' => '([a-z]+([a-z0-9]+)?){2,}', 'price_f' => '(\\d+)', 'price_t' => '(\\d+)', 'year_f' => '(\\d+)', 'year_t' => '(\\d+)', 'mile_f' => '(\\d+)', 'mile_t' => '(\\d+)', 'sort_f' => '(p|y|m)', 'sort_d' => '(a|d)', 'page' => '(\\d+)', 'format' => '(html|htm)'))->defaults(array('controller' => 'list')); Route::set('list', '(<city_pinyin>/)ershouche(/(b<brand_id>)(c<series_id>)(p<price_f>-<price_t>)(y<year_f>-<year_t>)(m<mile_f>-<mile_t>)(s<sort_f>-<sort_d>))(/p<page>)(.<format>)', array('city_pinyin' => '([a-z]+)', 'brand_id' => '(\\d+)', 'series_id' => '(\\d+)', 'price_f' => '(\\d+)', 'price_t' => '(\\d+)', 'year_f' => '(\\d+)', 'year_t' => '(\\d+)', 'mile_f' => '(\\d+)', 'mile_t' => '(\\d+)', 'sort_f' => '(p|y|m)', 'sort_d' => '(a|d)', 'page' => '(\\d+)', 'format' => '(html|htm)'))->defaults(array('controller' => 'list')); Route::set('detail', 'detail/<id>', array('id' => '(\\d+)'))->defaults(array('controller' => 'vehicle', 'action' => 'detail')); Route::set('custom', 'fruit/<customurl>', array('customurl' => '[a-z0-9_-]+'))->defaults(array('controller' => 'article', 'action' => 'customurl')); /* Route::set('manifest', '<name>.appcache', array('action' => '[a-z0-9_-]+')) ->defaults(array( 'controller' => 'manifest', 'action' => 'index' )); */ Route::set('default', '(<controller>(/<action>(/<id>)))', array('id' => '(\\d+)'))->defaults(array('controller' => 'home', 'action' => 'index')); Route::set('catch_all', '<path>', array('path' => '.*'))->defaults(array('controller' => 'Error', 'action' => '404')); if (!defined('KOHANA_START_TIME')) { define('KOHANA_START_TIME', microtime(TRUE)); } if (!defined('KOHANA_START_MEMORY')) { define('KOHANA_START_MEMORY', memory_get_usage()); } if (Kohana::$environment == Kohana::DEVELOPMENT) { echo Request::instance()->execute(); } else { try { echo Request::instance()->execute(); } catch (Exception $e) { Kohana_Exception::log($e); } }
/** * Get a Response object representing the exception * * @uses Kohana_Exception::text * @param Exception $e * @return Response */ public static function response(Exception $e) { try { Kohana_Exception::log($e); // Get the exception information $class = get_class($e); $code = $e->getCode(); $message = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); $trace = $e->getTrace(); /** * HTTP_Exceptions are constructed in the HTTP_Exception::factory() * method. We need to remove that entry from the trace and overwrite * the variables from above. */ if ($e instanceof HTTP_Exception and $trace[0]['function'] == 'factory') { extract(array_shift($trace)); } if ($e instanceof ErrorException) { /** * If XDebug is installed, and this is a fatal error, * use XDebug to generate the stack trace */ if (function_exists('xdebug_get_function_stack') and $code == E_ERROR) { $trace = array_slice(array_reverse(xdebug_get_function_stack()), 4); foreach ($trace as &$frame) { /** * XDebug pre 2.1.1 doesn't currently set the call type key * http://bugs.xdebug.org/view.php?id=695 */ if (!isset($frame['type'])) { $frame['type'] = '??'; } // XDebug also has a different name for the parameters array if (isset($frame['params']) and !isset($frame['args'])) { $frame['args'] = $frame['params']; } } } if (isset(Kohana_Exception::$php_errors[$code])) { // Use the human-readable error name $code = Kohana_Exception::$php_errors[$code]; } } /** * The stack trace becomes unmanageable inside PHPUnit. * * The error view ends up several GB in size, taking * serveral minutes to render. */ if (defined('PHPUnit_MAIN_METHOD')) { $trace = array_slice($trace, 0, 2); } // Instantiate the error view. $view = View::factory(Kohana_Exception::$error_view, get_defined_vars()); // Prepare the response object. $response = Response::factory(); // Set the response status $response->status($e instanceof HTTP_Exception ? $e->getCode() : 500); // Set the response headers $response->headers('Content-Type', Kohana_Exception::$error_view_content_type . '; charset=' . Kohana::$charset); // Set the response body $response->body($view->render()); } catch (Exception $e) { /** * Things are going badly for us, Lets try to keep things under control by * generating a simpler response object. */ $response = Response::factory(); $response->status(500); $response->headers('Content-Type', 'text/plain'); $response->body(Kohana_Exception::text($e)); } return $response; }