Expected.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * "Expected" HTTP exception class. Used for all [HTTP_Exception]'s where a standard
  4. * Kohana error page should never be shown.
  5. *
  6. * Eg [HTTP_Exception_301], [HTTP_Exception_302] etc
  7. *
  8. * @package Kohana
  9. * @category Exceptions
  10. * @author Kohana Team
  11. * @copyright (c) Kohana Team
  12. * @license https://koseven.ga/LICENSE.md
  13. */
  14. abstract class Kohana_HTTP_Exception_Expected extends HTTP_Exception {
  15. /**
  16. * @var Response Response Object
  17. */
  18. protected $_response;
  19. /**
  20. * Creates a new translated exception.
  21. *
  22. * throw new Kohana_Exception('Something went terrible wrong, :user',
  23. * array(':user' => $user));
  24. *
  25. * @param string $message status message, custom content to display with error
  26. * @param array $variables translation variables
  27. * @return void
  28. */
  29. public function __construct($message = NULL, array $variables = NULL, Exception $previous = NULL)
  30. {
  31. parent::__construct($message, $variables, $previous);
  32. // Prepare our response object and set the correct status code.
  33. $this->_response = Response::factory()
  34. ->status($this->_code);
  35. }
  36. /**
  37. * Gets and sets headers to the [Response].
  38. *
  39. * @see [Response::headers]
  40. * @param mixed $key
  41. * @param string $value
  42. * @return mixed
  43. */
  44. public function headers($key = NULL, $value = NULL)
  45. {
  46. $result = $this->_response->headers($key, $value);
  47. if ( ! $result instanceof Response)
  48. return $result;
  49. return $this;
  50. }
  51. /**
  52. * Validate this exception contains everything needed to continue.
  53. *
  54. * @throws Kohana_Exception
  55. * @return bool
  56. */
  57. public function check()
  58. {
  59. return TRUE;
  60. }
  61. /**
  62. * Generate a Response for the current Exception
  63. *
  64. * @uses Kohana_Exception::response()
  65. * @return Response
  66. */
  67. public function get_response()
  68. {
  69. $this->check();
  70. return $this->_response;
  71. }
  72. }