Expected.php 1.8 KB

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