Exception.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. abstract class Kohana_HTTP_Exception extends Kohana_Exception {
  3. /**
  4. * Creates an HTTP_Exception of the specified type.
  5. *
  6. * @param integer $code the http status code
  7. * @param string $message status message, custom content to display with error
  8. * @param array $variables translation variables
  9. * @return HTTP_Exception
  10. */
  11. public static function factory($code, $message = NULL, array $variables = NULL, Exception $previous = NULL)
  12. {
  13. $class = 'HTTP_Exception_'.$code;
  14. return new $class($message, $variables, $previous);
  15. }
  16. /**
  17. * @var int http status code
  18. */
  19. protected $_code = 0;
  20. /**
  21. * @var Request Request instance that triggered this exception.
  22. */
  23. protected $_request;
  24. /**
  25. * Creates a new translated exception.
  26. *
  27. * throw new Kohana_Exception('Something went terrible wrong, :user',
  28. * array(':user' => $user));
  29. *
  30. * @param string $message status message, custom content to display with error
  31. * @param array $variables translation variables
  32. * @return void
  33. */
  34. public function __construct($message = NULL, array $variables = NULL, Exception $previous = NULL)
  35. {
  36. parent::__construct($message, $variables, $this->_code, $previous);
  37. }
  38. /**
  39. * Store the Request that triggered this exception.
  40. *
  41. * @param Request $request Request object that triggered this exception.
  42. * @return HTTP_Exception
  43. */
  44. public function request(Request $request = NULL)
  45. {
  46. if ($request === NULL)
  47. return $this->_request;
  48. $this->_request = $request;
  49. return $this;
  50. }
  51. /**
  52. * Generate a Response for the current Exception
  53. *
  54. * @uses Kohana_Exception::response()
  55. * @return Response
  56. */
  57. public function get_response()
  58. {
  59. return Kohana_Exception::response($this);
  60. }
  61. }