Error_Page.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Error page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::PAGE . "Page.php");
  12. /**
  13. * Error page model.
  14. *
  15. * @category Page
  16. */
  17. class Error_Page extends Page{
  18. /**
  19. * @var int Error code.
  20. */
  21. private $code = 500;
  22. /**
  23. * @var string Error description.
  24. */
  25. private $message = "";
  26. /**
  27. * Constructor.
  28. *
  29. * Retrieves the data and initializes the variables.
  30. *
  31. * @param int $code HTTP Error code. Optional, default 500.
  32. */
  33. public function __construct($code = null){
  34. $this->view = PATH::VIEW . "error.php";
  35. $this->title = "Error - SWDB";
  36. if (null == $code || intval($code) < 200 || intval($code) > 599){
  37. $code = 500;
  38. }
  39. switch(intval($code)){
  40. case 400:
  41. $this->message = "Invalid request";
  42. break;
  43. case 404:
  44. $this->message = "Not found";
  45. break;
  46. case 500:
  47. $this->message = "Server error";
  48. break;
  49. default:
  50. $this->message = "Unknown error";
  51. }
  52. $this->code = intval($code);
  53. }
  54. /**
  55. * Retrieves the error code.
  56. *
  57. * @return int HTTP error code
  58. */
  59. public function get_code(){
  60. return $this->code;
  61. }
  62. /**
  63. * Retrieves the error description.
  64. *
  65. * @return int HTTP error description.
  66. */
  67. public function get_message(){
  68. return $this->message;
  69. }
  70. }