handler() public static method

Inline exception handler, displays the error message, source of the exception, and the stack trace of the error.
public static handler ( Exception $e ) : boolean
$e Exception
return boolean
Esempio n. 1
0
 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             // Посылаем статус страницы 404
             $response = new Response();
             $response->status(404);
             $response->protocol('HTTP/1.1');
             // Посылаем корректный статус 404 ошибки
             /* header('HTTP/1.0 404 Not Found');
                header('HTTP/1.1 404 Not Found');
                header('Status: 404 Not Found'); */
             // Создаем вид для отображения 404 ошибки
             $view = new View_Error_404('error/404');
             $view->message = $e->getMessage();
             // Если шаблон есть - отображаем страницу ошибки
             if (!empty($view)) {
                 // Выводим шаблон
                 echo $response->send_headers()->body($view->render());
             } else {
                 echo $response->body('<h1>Не найден шаблон для View_Error_404</h1>');
             }
             return true;
             break;
         default:
             Kohana_Exception::handler($e);
     }
 }
Esempio n. 2
0
 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             $view = new View('errors/error404');
             Controller_Abstract::add_static();
             if (Kohana::$environment == Kohana::DEVELOPMENT) {
                 $view->message = $e->getMessage();
             }
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         case 'HTTP_Exception_410':
             $response = new Response();
             $response->status(410);
             $view = new View('errors/error410');
             Controller_Abstract::add_static();
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         default:
             header('C-Data: ' . uniqid() . str_replace('=', '', base64_encode($e->getMessage())));
             return Kohana_Exception::handler($e);
             break;
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public static function exceptionHandler($exception)
 {
     parent::exceptionHandler($exception);
     if (Kohana::$errors === true) {
         Kohana_Exception::handler($exception);
     }
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public static function exceptionHandler($exception)
 {
     $session = Session::instance();
     $session_data = $session->as_array();
     parent::notifyException($exception, $session_data);
     if (Kohana::$errors === true) {
         Kohana_Exception::handler($exception);
     }
 }
Esempio n. 5
0
 public function __toString()
 {
     try {
         return (string) $this->render();
     } catch (Exception $e) {
         // Display the exception message
         Kohana_Exception::handler($e);
         return '';
     }
 }
Esempio n. 6
0
 /**
  * Provides auto-loading support for the Authorize.Net classes.
  *
  * You should never have to call this function, as simply calling a class
  * will cause it to be called.
  *
  * This function must be enabled as an autoloader in the bootstrap or module init:
  *
  *     spl_autoload_register(array('AuthorizeNet', 'auto_load'));
  *
  * @param   string   class name
  * @return  boolean
  */
 public static function auto_load($class)
 {
     try {
         if (0 === stripos($class, 'authorizenet')) {
             require_once Kohana::find_file('vendor', 'anet_php_sdk/AuthorizeNet');
         }
         return class_exists($class);
     } catch (Exception $e) {
         Kohana_Exception::handler($e);
         die;
     }
 }
Esempio n. 7
0
 public static function auto_load($class)
 {
     try {
         if (0 === stripos($class, 'stripe')) {
             require_once Kohana::find_file('vendor', 'lib/Stripe');
         }
         return class_exists($class);
     } catch (Exception $e) {
         Kohana_Exception::handler($e);
         die;
     }
 }
Esempio n. 8
0
 /**
  * Tests Kohana_Exception::handler()
  *
  * @test
  * @dataProvider provider_handler
  * @covers Kohana_Exception::handler
  * @param boolean $exception_type    Exception type to throw
  * @param boolean $message           Message to pass to exception
  * @param boolean $is_cli            Use cli mode?
  * @param boolean $expected          Output for Kohana_Exception::handler
  * @param string  $expected_message  What to look for in the output string
  */
 public function teste_handler($exception_type, $message, $is_cli, $expected, $expected_message)
 {
     try {
         Kohana::$is_cli = $is_cli;
         throw new $exception_type($message);
     } catch (Exception $e) {
         ob_start();
         $this->assertEquals($expected, Kohana_Exception::handler($e));
         $view = ob_get_contents();
         ob_clean();
         $this->assertContains($expected_message, $view);
     }
     Kohana::$is_cli = TRUE;
 }
Esempio n. 9
0
 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             $request = Request::factory('404error')->method(Request::POST)->post(array('message' => $e->getMessage()))->execute();
             echo $response->body($request)->send_headers()->body();
             return TRUE;
             break;
         default:
             return Kohana_Exception::handler($e);
             break;
     }
 }
Esempio n. 10
0
 /**
  * Renders the pagination links.
  *
  * @return  string  pagination output (HTML)
  */
 public function __toString()
 {
     try {
         return $this->render();
     } catch (Exception $e) {
         // Display the exception message only if not in production
         ob_start();
         Kohana_Exception::handler($e);
         if (Kohana::$environment == Kohana::PRODUCTION) {
             ob_end_clean();
             return __('An error occured and has been logged.');
         } else {
             return ob_get_clean();
         }
     }
 }
Esempio n. 11
0
 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'Http_Exception_404':
             $response = new Response();
             $response->status(404);
             $view = new View('404view');
             $view->message = $e->getMessage();
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         default:
             return Kohana_Exception::handler($e);
             break;
     }
 }
Esempio n. 12
0
	public static function handle(Exception $e)
	{
		switch (get_class($e))
		{
			case 'HTTP_Exception_404':
				echo Response::factory()
					->status(404)
					->body(new View('404'))
					->send_headers()
					->body();
				return TRUE;
			break;
			default:
				return Kohana_Exception::handler($e);
		}
	}
Esempio n. 13
0
 /**
  * Inline exception handler.
  *
  * @param   Exception  exception object
  * @return  string
  * @uses    Arr::get
  * @uses    Kohana::find_file
  * @uses    Kohana_Exception::handler
  * @uses    Kohana_Exception::text
  */
 function kandler(Exception $e)
 {
     try {
         // Get error code
         $code = $e->getCode();
         // Retrieve Kandler's config
         $config = Kohana::$config->load('kandler');
         // Use views defined by user or use default
         $view = Arr::get($config->errors, $code, $code);
         // Create path to error view
         $path = $config->path . DIRECTORY_SEPARATOR . $view;
         if (Kohana::find_file('views', $path)) {
             // Set an exception view
             Kohana_Exception::$error_view = $path;
         }
         // Handle an exception using Kohana's handler
         Kohana_Exception::handler($e);
     } catch (Exception $e) {
         return Kohana_Exception::text($e);
     }
 }
 public static function handler(Exception $e)
 {
     /*
      * In development, use the in-built Kohana
      * exception handler to display and log the
      * exception/error.
      */
     if (Kohana::$environment >= Kohana::DEVELOPMENT) {
         Kohana_Exception::handler($e);
     } else {
         try {
             $exception_text = Kohana_Exception::text($e);
             // Log the error
             Kohana::$log->add(Log::ERROR, $exception_text);
             // Email the error
             if (class_exists('Email')) {
                 $email_subject = Kohana::$config->load('error.website.name') . ' Error';
                 $email_message = $exception_text;
                 $email_from = Kohana::$config->load('error.email.from');
                 foreach ('error.email.to' as $email_to) {
                     Email::send($email_to, $email_from, $email_subject, $email_mesage);
                 }
             } else {
                 Kohana::$log->add(Log::NOTICE, 'Email module not installed, errors can not be sent.');
             }
             // Show an error page
             $action = $e instanceof HTTP_Exception ? $e->getCode() : 500;
             $post = array('message' => $e->getMessage(), 'requested_url' => Request::$current ? Request::$current->uri() : 'Unknown');
             echo Request::factory(Route::get('error-handler')->uri(array('action' => $action)))->method(Request::POST)->post($post)->execute()->send_headers()->body();
         } 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);
             // Exit with an error status
             exit(1);
         }
     }
 }
Esempio n. 15
0
 public static function handle(Exception $e)
 {
     if (Kohana::$environment === Kohana::DEVELOPMENT) {
         parent::handler($e);
     } else {
         switch (get_class($e)) {
             case 'HTTP_Exception_404':
                 //echo HTML::render_action('404', 'error');
                 $request = Request::current();
                 $response = $request->create_response();
                 $response->status($e->getCode());
                 $view = View::factory('error/404');
                 $view->message = $e->getMessage();
                 $view->title = 'File Not Found';
                 echo $response->body($view)->send_headers()->body();
                 return TRUE;
                 break;
             default:
                 return Kohana_Exception::handler($e);
                 break;
         }
     }
 }
Esempio n. 16
0
 /**
  * Catches errors that are not caught by the error handler, such as E_PARSE.
  *
  * @uses    Kohana_Exception::handler
  * @return  void
  */
 public static function shutdown_handler()
 {
     if (!Kohana::$_init) {
         // Do not execute when not active
         return;
     }
     try {
         if (Kohana::$caching === TRUE and Kohana::$_files_changed === TRUE) {
             // Write the file path cache
             Kohana::cache('Kohana::find_file()', Kohana::$_files);
         }
     } catch (Exception $e) {
         // Pass the exception to the handler
         Kohana_Exception::handler($e);
     }
     if (Kohana::$errors and $error = error_get_last() and in_array($error['type'], Kohana::$shutdown_errors)) {
         // Clean the output buffer
         ob_get_level() and ob_clean();
         // Fake an exception for nice debugging
         Kohana_Exception::handler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
         // Shutdown now to avoid a "death loop"
         exit(1);
     }
 }
Esempio n. 17
0
 /**
  * Renders the pagination links.
  *
  * @return  string  pagination output (HTML)
  */
 public function __toString()
 {
     try {
         return $this->render();
     } catch (Exception $e) {
         Kohana_Exception::handler($e);
         return '';
     }
 }
Esempio n. 18
0
 /**
  * Provides auto-loading support of Kohana classes, as well as transparent
  * extension of classes that have a _Core suffix.
  *
  * Class names are converted to file names by making the class name
  * lowercase and converting underscores to slashes:
  *
  *     // Loads classes/my/class/name.php
  *     Kohana::auto_load('My_Class_Name');
  *
  * @param   string   class name
  * @return  boolean
  */
 public static function auto_load($class)
 {
     try {
         $class = strtolower($class);
         // Transform the class name into a path
         $file = str_replace('_', '/', $class);
         if ($path = Kohana::find_file('classes', $file)) {
             // Load the class file
             require $path;
             if (self::$_files !== NULL and !isset(self::$skip_classes[$class])) {
                 self::$_files[] = $path;
             }
             // Class has been found
             return TRUE;
         }
         // Class is not in the filesystem
         return FALSE;
     } catch (Exception $e) {
         Kohana_Exception::handler($e);
         die;
     }
 }
Esempio n. 19
0
	/**
	 * Displays the error
	 *
	 * @param	 array	$options	Options from config
	 * @return	void
	 */
	protected function _action_display(array $options = array())
	{
		if (((Kohana::$environment > Kohana::STAGING) and ($this->request_initial->query('show_error') == 'true')) or ($this->request_initial->query('display_token') == $this->config('display_token', false)))
		{
			Kohana_Exception::handler($this->exception);
			exit(1);
		}
		$view = Arr::get($options, 'view', 'errors/_default');

		$this->display = $this->render($view);

		echo $this->display;
	}
Esempio n. 20
0
 /**
  * Magic method, returns the output of render(). If any exceptions are
  * thrown, the exception output will be returned instead.
  * @return  string
  */
 public function __toString()
 {
     try {
         return $this->render();
     } catch (Exception $e) {
         // Display the exception message
         if (substr(Kohana::VERSION, 0, 3) == '3.0') {
             Kohana::exception_handler($e);
         } else {
             Kohana_Exception::handler($e);
         }
         return '';
     }
 }
Esempio n. 21
0
 /**
  * Magic method, returns the output of [Kostache::render].
  *
  * @return  string
  * @uses    Kostache::render
  */
 public function __toString()
 {
     try {
         return $this->render();
     } catch (Exception $e) {
         ob_start();
         // Render the exception
         Kohana_Exception::handler($e);
         return (string) ob_get_clean();
     }
 }
Esempio n. 22
0
 public static function shutdown_handler()
 {
     if (!Kohana::$_init) {
         return;
     }
     if (Kohana::$errors and $error = error_get_last() and in_array($error['type'], Kohana::$shutdown_errors)) {
         ob_get_level() and ob_clean();
         Kohana_Exception::handler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
         exit(1);
     }
 }