MinzException.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. class MinzException extends Exception {
  3. const ERROR = 0;
  4. const WARNING = 10;
  5. const NOTICE = 20;
  6. public function __construct ($message, $code = self::ERROR) {
  7. if ($code != MinzException::ERROR
  8. && $code != MinzException::WARNING
  9. && $code != MinzException::NOTICE) {
  10. $code = MinzException::ERROR;
  11. }
  12. parent::__construct ($message, $code);
  13. }
  14. }
  15. class PermissionDeniedException extends MinzException {
  16. public function __construct ($file_name, $code = self::ERROR) {
  17. $message = 'Permission is denied for `' . $file_name.'`';
  18. parent::__construct ($message, $code);
  19. }
  20. }
  21. class FileNotExistException extends MinzException {
  22. public function __construct ($file_name, $code = self::ERROR) {
  23. $message = 'File doesn\'t exist : `' . $file_name.'`';
  24. parent::__construct ($message, $code);
  25. }
  26. }
  27. class BadConfigurationException extends MinzException {
  28. public function __construct ($part_missing, $code = self::ERROR) {
  29. $message = '`' . $part_missing
  30. . '` in the configuration file is missing';
  31. parent::__construct ($message, $code);
  32. }
  33. }
  34. class ControllerNotExistException extends MinzException {
  35. public function __construct ($controller_name, $code = self::ERROR) {
  36. $message = 'Controller `' . $controller_name
  37. . '` doesn\'t exist';
  38. parent::__construct ($message, $code);
  39. }
  40. }
  41. class ControllerNotActionControllerException extends MinzException {
  42. public function __construct ($controller_name, $code = self::ERROR) {
  43. $message = 'Controller `' . $controller_name
  44. . '` isn\'t instance of ActionController';
  45. parent::__construct ($message, $code);
  46. }
  47. }
  48. class ActionException extends MinzException {
  49. public function __construct ($controller_name, $action_name, $code = self::ERROR) {
  50. $message = '`' . $action_name . '` cannot be invoked on `'
  51. . $controller_name . '`';
  52. parent::__construct ($message, $code);
  53. }
  54. }
  55. class RouteNotFoundException extends MinzException {
  56. private $route;
  57. public function __construct ($route, $code = self::ERROR) {
  58. $this->route = $route;
  59. $message = 'Route `' . $route . '` not found';
  60. parent::__construct ($message, $code);
  61. }
  62. public function route () {
  63. return $this->route;
  64. }
  65. }
  66. class PDOConnectionException extends MinzException {
  67. public function __construct ($string_connection, $user, $code = self::ERROR) {
  68. $message = 'Access to database is denied for `' . $user . '`'
  69. . ' (`' . $string_connection . '`)';
  70. parent::__construct ($message, $code);
  71. }
  72. }
  73. class CurrentPagePaginationException extends MinzException {
  74. public function __construct ($page) {
  75. $message = 'Page number `' . $page . '` doesn\'t exist';
  76. parent::__construct ($message, self::ERROR);
  77. }
  78. }