Class Kohana_HTTP_Exception_305

Kohana_HTTP_Exception_305

extends HTTP_Exception_Expected
extends Kohana_HTTP_Exception_Expected
extends HTTP_Exception
extends Kohana_HTTP_Exception
extends Kohana_Exception
extends Kohana_Kohana_Exception
extends Exception

Implements: Throwable

"Expected" HTTP exception class. Used for all HTTP_Exception's where a standard Kohana error page should never be shown.

Eg HTTP_Exception_301, HTTP_Exception_302 etc

package
Kohana
category
Exceptions
author
Kohana Team
copyright
(c) Kohana Team
license
https://koseven.ga/LICENSE.md


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 integer $_code

HTTP 305 Use Proxy

Default value:
integer 305

protected Request $_request

Request instance that triggered this exception.

Default value:
NULL

protected Response $_response

Response Object

Default value:
NULL

protected $code

Default value:
integer 0

protected $file

Default value:
NULL

protected $line

Default value:
NULL

protected $message

Default value:
string(0) ""

Methods

public check() (defined in Kohana_HTTP_Exception_305)

Validate this exception contains everything needed to continue.

Tags

Return Values

  • bool

Source Code

public function check()
{
	if ($location = $this->headers('location') === NULL)
		throw new Kohana_Exception('A \'location\' must be specified for a redirect');

	if (strpos($location, '://') === FALSE)
		throw new Kohana_Exception('An absolute URI to the proxy server must be specified');

	return TRUE;
}

public location([ string $uri = NULL ] ) (defined in Kohana_HTTP_Exception_305)

Specifies the proxy to replay this request via

Parameters

  • string $uri = NULL - $location URI of the proxy

Source Code

public function location($uri = NULL)
{
	if ($uri === NULL)
		return $this->headers('Location');

	$this->headers('Location', $uri);

	return $this;
}

public __construct([ string $message = NULL , array $variables = NULL , $previous = NULL ] ) (defined in Kohana_HTTP_Exception_Expected)

Creates a new translated exception.

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

Parameters

  • string $message = NULL - Status message, custom content to display with error
  • array $variables = NULL - Translation variables
  • unknown $previous = NULL

Return Values

  • void

Source Code

public function __construct($message = NULL, array $variables = NULL, Exception $previous = NULL)
{
	parent::__construct($message, $variables, $previous);

	// Prepare our response object and set the correct status code.
	$this->_response = Response::factory()
		->status($this->_code);
}

public get_response() (defined in Kohana_HTTP_Exception_Expected)

Generate a Response for the current Exception

Tags

Return Values

  • Response

Source Code

public function get_response()
{
	$this->check();

	return $this->_response;
}

public headers([ mixed $key = NULL , string $value = NULL ] ) (defined in Kohana_HTTP_Exception_Expected)

Gets and sets headers to the Response.

Parameters

  • mixed $key = NULL - $key
  • string $value = NULL - $value

Tags

  • See - [Response::headers]

Return Values

  • mixed

Source Code

public function headers($key = NULL, $value = NULL)
{
	$result = $this->_response->headers($key, $value);

	if ( ! $result instanceof Response)
		return $result;

	return $this;
}

public static factory(integer $code [, string $message = NULL , array $variables = NULL , $previous = NULL ] ) (defined in Kohana_HTTP_Exception)

Creates an HTTP_Exception of the specified type.

Parameters

  • integer $code required - The http status code
  • string $message = NULL - Status message, custom content to display with error
  • array $variables = NULL - Translation variables
  • unknown $previous = NULL

Return Values

  • HTTP_Exception

Source Code

public static function factory($code, $message = NULL, array $variables = NULL, Exception $previous = NULL)
{
	$class = 'HTTP_Exception_'.$code;

	return new $class($message, $variables, $previous);
}

public request([ Request $request = NULL ] ) (defined in Kohana_HTTP_Exception)

Store the Request that triggered this exception.

Parameters

  • Request $request = NULL - Request object that triggered this exception.

Return Values

  • HTTP_Exception

Source Code

public function request(Request $request = NULL)
{
	if ($request === NULL)
		return $this->_request;

	$this->_request = $request;

	return $this;
}

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($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 handler(Exception $e ) (defined in Kohana_Kohana_Exception)

Inline exception handler, displays the error message, source of the exception, and the stack trace of the error.

Parameters

  • Exception $e required - $e

Tags

Return Values

  • void

Source Code

public static function handler($e)
{
    $response = Kohana_Exception::_handler($e);

    // Send the response to the browser
    echo $response->send_headers()->body();

    exit(1);
}

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

Logs an exception.

Parameters

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

Tags

Return Values

  • void

Source Code

public static function log($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, ['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($e)
{
    if ( ! $e instanceof Exception AND ! $e instanceof Throwable )
        throw InvalidArgumentException;

    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 returns the words 'dynamic' and 'static' instead of using '->' and '::' symbols
                    if ('dynamic' === $frame['type'])
                    {
                        $frame['type'] = '->';
                    }
                    elseif ('static' === $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')
            OR
            defined('PHPUNIT_COMPOSER_INSTALL')
            OR
            defined('__PHPUNIT_PHAR__')
        )
        {
            $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($e)
{
    if ( ! $e instanceof Exception AND ! $e instanceof Throwable )
        throw InvalidArgumentException;

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

public __wakeup() (defined in Exception)

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)

Do you want to contribute to Koseven?

We need YOUR help!

This project is open source. What does this mean? YOU can help:
  • Found a bug? Report it on Github
  • Need a feature? Add it Here
  • Want to help? Join the Forum
Go to Github