1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace ICanBoogie\HTTP;
13
14 use ICanBoogie\PropertyNotDefined;
15
16 17 18
19 class HTTPError extends \Exception
20 {
21
22 }
23
24 25 26
27 class NotFound extends HTTPError
28 {
29 public function __construct($message='The requested URL was not found on this server.', $code=404, \Exception $previous=null)
30 {
31 parent::__construct($message, $code, $previous);
32 }
33 }
34
35 36 37 38
39 class ServiceUnavailable extends HTTPError
40 {
41 public function __construct($message="The server is currently unavailable (because it is overloaded or down for maintenance).", $code=503, \Exception $previous=null)
42 {
43 parent::__construct($message, $code, $previous);
44 }
45 }
46
47 48 49
50 class MethodNotSupported extends HTTPError
51 {
52 public function __construct($method, $code=500, \Exception $previous=null)
53 {
54 parent::__construct(\ICanboogie\format('Method not supported: %method', array('method' => $method)), $code, $previous);
55 }
56 }
57
58 59 60
61 class StatusCodeNotValid extends \InvalidArgumentException
62 {
63 public function __construct($status_code, $code=500, \Exception $previous=null)
64 {
65 parent::__construct("Status code not valid: {$status_code}.", $code, $previous);
66 }
67 }
68
69 70 71 72 73
74 class ForceRedirect extends HTTPError
75 {
76 private $location;
77
78 public function __construct($location, $code=302, \Exception $previous=null)
79 {
80 $this->location = $location;
81
82 parent::__construct("Location: $location", $code, $previous);
83 }
84
85 public function __get($property)
86 {
87 if ($property == 'location')
88 {
89 return $this->location;
90 }
91
92 throw new PropertyNotDefined(array($property, $this));
93 }
94 }