Modules

Minion_Exception
extends Kohana_Minion_Exception
extends Kohana_Exception
extends Kohana_Kohana_Exception
extends Exception

Minipn exception

package
Kohana
category
Minion
author
Kohana Team
copyright
© 2009-2011 Kohana Team
license
http://kohanaframework.org/license

Class declared in MODPATH/minion/classes/Minion/Exception.php on line 3.

Properties

public static string $error_view

error rendering view

string(12) "kohana/error"

public static string $error_view_content_type

error view content type

string(9) "text/html"

public static array $php_errors

PHP error code => human readable name

array(9) (
    1 => string(11) "Fatal Error"
    256 => string(10) "User Error"
    4 => string(11) "Parse Error"
    2 => string(7) "Warning"
    512 => string(12) "User Warning"
    2048 => string(6) "Strict"
    8 => string(6) "Notice"
    4096 => string(17) "Recoverable Error"
    8192 => string(10) "Deprecated"
)

protected $code

Default value:
integer 0

protected $file

Default value:
NULL

protected $line

Default value:
NULL

protected $message

Default value:
string(0) ""

Methods

public format_for_cli( ) (defined in Kohana_Minion_Exception)

Source Code

public function format_for_cli()
{
	return Kohana_Exception::text($this);
}

public static handler( Exception $e ) (defined in Kohana_Minion_Exception)

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.

Should this still log? Maybe not as useful since we'll see the error on the screen.

Parameters

  • Exception $e required - $e

Tags

Return Values

  • boolean

Source Code

public static function handler(Exception $e)
{
	try
	{
		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 __construct( [ string $message = string(0) "" , array $variables = NULL , integer|string $code = integer 0 , Exception $previous = NULL ] ) (defined in Kohana_Kohana_Exception)

Creates a new translated exception.

throw new Kohana_Exception('Something went terrible wrong, :user',
    array(':user' => $user));

Parameters

  • string $message = string(0) "" - Error message
  • array $variables = NULL - Translation variables
  • integer|string $code = integer 0 - The exception code
  • Exception $previous = NULL - Previous exception

Return Values

  • void

Source Code

public function __construct($message = "", array $variables = NULL, $code = 0, Exception $previous = NULL)
{
	// Set the message
	$message = __($message, $variables);

	// Pass the message and integer code to the parent
	parent::__construct($message, (int) $code, $previous);

	// Save the unmodified code
	// @link http://bugs.php.net/39615
	$this->code = $code;
}

public __toString( ) (defined in Kohana_Kohana_Exception)

Magic object-to-string method.

echo $exception;

Tags

Return Values

  • string

Source Code

public function __toString()
{
	return Kohana_Exception::text($this);
}

public static _handler( Exception $e ) (defined in Kohana_Kohana_Exception)

Exception handler, logs the exception and generates a Response object for display.

Parameters

  • Exception $e required - $e

Tags

Return Values

  • Response

Source Code

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);
	}
}

public static log( Exception $e [, int $level = integer 0 ] ) (defined in Kohana_Kohana_Exception)

Logs an exception.

Parameters

  • Exception $e required - $e
  • int $level = integer 0 - $level

Tags

Return Values

  • void

Source Code

public static function log(Exception $e, $level = Log::EMERGENCY)
{
	if (is_object(Kohana::$log))
	{
		// Create a text version of the exception
		$error = Kohana_Exception::text($e);

		// Add this exception to the log
		Kohana::$log->add($level, $error, NULL, array('exception' => $e));

		// Make sure the logs are written
		Kohana::$log->write();
	}
}

public static response( Exception $e ) (defined in Kohana_Kohana_Exception)

Get a Response object representing the exception

Parameters

  • Exception $e required - $e

Tags

Return Values

  • Response

Source Code

public static function response(Exception $e)
{
	try
	{
		// 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;
}

public static text( Exception $e ) (defined in Kohana_Kohana_Exception)

Get a single line of text representing the exception:

Error [ Code ]: Message ~ File [ Line ]

Parameters

  • Exception $e required - $e

Return Values

  • string

Source Code

public static function text(Exception $e)
{
	return sprintf('%s [ %s ]: %s ~ %s [ %d ]',
		get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine());
}

final public getCode( ) (defined in Exception)

final public getFile( ) (defined in Exception)

final public getLine( ) (defined in Exception)

final public getMessage( ) (defined in Exception)

final public getPrevious( ) (defined in Exception)

final public getTrace( ) (defined in Exception)

final public getTraceAsString( ) (defined in Exception)

final private __clone( ) (defined in Exception)