@@ -19,120 +19,120 @@ |
||
19 | 19 | |
20 | 20 | class RestException extends Exception |
21 | 21 | { |
22 | - /** |
|
23 | - * HTTP status codes |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - public static $codes = array( |
|
28 | - 100 => 'Continue', |
|
29 | - 101 => 'Switching Protocols', |
|
30 | - 200 => 'OK', |
|
31 | - 201 => 'Created', |
|
32 | - 202 => 'Accepted', |
|
33 | - 203 => 'Non-Authoritative Information', |
|
34 | - 204 => 'No Content', |
|
35 | - 205 => 'Reset Content', |
|
36 | - 206 => 'Partial Content', |
|
37 | - 300 => 'Multiple Choices', |
|
38 | - 301 => 'Moved Permanently', |
|
39 | - 302 => 'Found', |
|
40 | - 303 => 'See Other', |
|
41 | - 304 => 'Not Modified', |
|
42 | - 305 => 'Use Proxy', |
|
43 | - 306 => '(Unused)', |
|
44 | - 307 => 'Temporary Redirect', |
|
45 | - 400 => 'Bad Request', |
|
46 | - 401 => 'Unauthorized', |
|
47 | - 402 => 'Payment Required', |
|
48 | - 403 => 'Forbidden', |
|
49 | - 404 => 'Not Found', |
|
50 | - 405 => 'Method Not Allowed', |
|
51 | - 406 => 'Not Acceptable', |
|
52 | - 407 => 'Proxy Authentication Required', |
|
53 | - 408 => 'Request Timeout', |
|
54 | - 409 => 'Conflict', |
|
55 | - 410 => 'Gone', |
|
56 | - 411 => 'Length Required', |
|
57 | - 412 => 'Precondition Failed', |
|
58 | - 413 => 'Request Entity Too Large', |
|
59 | - 414 => 'Request-URI Too Long', |
|
60 | - 415 => 'Unsupported Media Type', |
|
61 | - 416 => 'Requested Range Not Satisfiable', |
|
62 | - 417 => 'Expectation Failed', |
|
63 | - 429 => 'Too Many Requests', //still in draft but used for rate limiting |
|
64 | - 500 => 'Internal Server Error', |
|
65 | - 501 => 'Not Implemented', |
|
66 | - 502 => 'Bad Gateway', |
|
67 | - 503 => 'Service Unavailable', |
|
68 | - 504 => 'Gateway Timeout', |
|
69 | - 505 => 'HTTP Version Not Supported' |
|
70 | - ); |
|
71 | - private $details; |
|
72 | - private $stage; |
|
22 | + /** |
|
23 | + * HTTP status codes |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + public static $codes = array( |
|
28 | + 100 => 'Continue', |
|
29 | + 101 => 'Switching Protocols', |
|
30 | + 200 => 'OK', |
|
31 | + 201 => 'Created', |
|
32 | + 202 => 'Accepted', |
|
33 | + 203 => 'Non-Authoritative Information', |
|
34 | + 204 => 'No Content', |
|
35 | + 205 => 'Reset Content', |
|
36 | + 206 => 'Partial Content', |
|
37 | + 300 => 'Multiple Choices', |
|
38 | + 301 => 'Moved Permanently', |
|
39 | + 302 => 'Found', |
|
40 | + 303 => 'See Other', |
|
41 | + 304 => 'Not Modified', |
|
42 | + 305 => 'Use Proxy', |
|
43 | + 306 => '(Unused)', |
|
44 | + 307 => 'Temporary Redirect', |
|
45 | + 400 => 'Bad Request', |
|
46 | + 401 => 'Unauthorized', |
|
47 | + 402 => 'Payment Required', |
|
48 | + 403 => 'Forbidden', |
|
49 | + 404 => 'Not Found', |
|
50 | + 405 => 'Method Not Allowed', |
|
51 | + 406 => 'Not Acceptable', |
|
52 | + 407 => 'Proxy Authentication Required', |
|
53 | + 408 => 'Request Timeout', |
|
54 | + 409 => 'Conflict', |
|
55 | + 410 => 'Gone', |
|
56 | + 411 => 'Length Required', |
|
57 | + 412 => 'Precondition Failed', |
|
58 | + 413 => 'Request Entity Too Large', |
|
59 | + 414 => 'Request-URI Too Long', |
|
60 | + 415 => 'Unsupported Media Type', |
|
61 | + 416 => 'Requested Range Not Satisfiable', |
|
62 | + 417 => 'Expectation Failed', |
|
63 | + 429 => 'Too Many Requests', //still in draft but used for rate limiting |
|
64 | + 500 => 'Internal Server Error', |
|
65 | + 501 => 'Not Implemented', |
|
66 | + 502 => 'Bad Gateway', |
|
67 | + 503 => 'Service Unavailable', |
|
68 | + 504 => 'Gateway Timeout', |
|
69 | + 505 => 'HTTP Version Not Supported' |
|
70 | + ); |
|
71 | + private $details; |
|
72 | + private $stage; |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param int $httpStatusCode http status code |
|
76 | - * @param string|null $errorMessage error message |
|
77 | - * @param array $details any extra detail about the exception |
|
78 | - * @param Exception $previous previous exception if any |
|
79 | - */ |
|
80 | - public function __construct($httpStatusCode, $errorMessage = null, array $details = array(), Exception $previous = null) |
|
81 | - { |
|
82 | - $events = Scope::get('Restler')->getEvents(); |
|
83 | - if(count($events)<= 1){ |
|
84 | - $this->stage = 'setup'; |
|
85 | - } else { |
|
86 | - $this->stage = $previous ? $events[count($events)-2] : end($events); |
|
87 | - } |
|
88 | - $this->details = $details; |
|
89 | - parent::__construct($errorMessage, $httpStatusCode, $previous); |
|
90 | - } |
|
74 | + /** |
|
75 | + * @param int $httpStatusCode http status code |
|
76 | + * @param string|null $errorMessage error message |
|
77 | + * @param array $details any extra detail about the exception |
|
78 | + * @param Exception $previous previous exception if any |
|
79 | + */ |
|
80 | + public function __construct($httpStatusCode, $errorMessage = null, array $details = array(), Exception $previous = null) |
|
81 | + { |
|
82 | + $events = Scope::get('Restler')->getEvents(); |
|
83 | + if(count($events)<= 1){ |
|
84 | + $this->stage = 'setup'; |
|
85 | + } else { |
|
86 | + $this->stage = $previous ? $events[count($events)-2] : end($events); |
|
87 | + } |
|
88 | + $this->details = $details; |
|
89 | + parent::__construct($errorMessage, $httpStatusCode, $previous); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Get extra details about the exception |
|
94 | - * |
|
95 | - * @return array details array |
|
96 | - */ |
|
97 | - public function getDetails() |
|
98 | - { |
|
99 | - return $this->details; |
|
100 | - } |
|
92 | + /** |
|
93 | + * Get extra details about the exception |
|
94 | + * |
|
95 | + * @return array details array |
|
96 | + */ |
|
97 | + public function getDetails() |
|
98 | + { |
|
99 | + return $this->details; |
|
100 | + } |
|
101 | 101 | |
102 | - public function getStage() |
|
103 | - { |
|
104 | - return $this->stage; |
|
105 | - } |
|
102 | + public function getStage() |
|
103 | + { |
|
104 | + return $this->stage; |
|
105 | + } |
|
106 | 106 | |
107 | - public function getStages() |
|
108 | - { |
|
109 | - $e = Scope::get('Restler')->getEvents(); |
|
110 | - $i = array_search($this->stage, $e); |
|
111 | - return array( |
|
112 | - 'success' => array_slice($e, 0, $i), |
|
113 | - 'failure' => array_slice($e, $i), |
|
114 | - ); |
|
115 | - } |
|
107 | + public function getStages() |
|
108 | + { |
|
109 | + $e = Scope::get('Restler')->getEvents(); |
|
110 | + $i = array_search($this->stage, $e); |
|
111 | + return array( |
|
112 | + 'success' => array_slice($e, 0, $i), |
|
113 | + 'failure' => array_slice($e, $i), |
|
114 | + ); |
|
115 | + } |
|
116 | 116 | |
117 | - public function getErrorMessage() |
|
118 | - { |
|
119 | - $statusCode = $this->getCode(); |
|
120 | - $message = $this->getMessage(); |
|
121 | - if (isset(RestException::$codes[$statusCode])) { |
|
122 | - $message = RestException::$codes[$statusCode] . |
|
123 | - (empty($message) ? '' : ': ' . $message); |
|
124 | - } |
|
125 | - return $message; |
|
126 | - } |
|
117 | + public function getErrorMessage() |
|
118 | + { |
|
119 | + $statusCode = $this->getCode(); |
|
120 | + $message = $this->getMessage(); |
|
121 | + if (isset(RestException::$codes[$statusCode])) { |
|
122 | + $message = RestException::$codes[$statusCode] . |
|
123 | + (empty($message) ? '' : ': ' . $message); |
|
124 | + } |
|
125 | + return $message; |
|
126 | + } |
|
127 | 127 | |
128 | - public function getSource() |
|
129 | - { |
|
130 | - $e = $this; |
|
131 | - while ($e->getPrevious()) { |
|
132 | - $e = $e->getPrevious(); |
|
133 | - } |
|
134 | - return basename($e->getFile()) . ':' |
|
135 | - . $e->getLine() . ' at ' |
|
136 | - . $this->getStage() . ' stage'; |
|
137 | - } |
|
128 | + public function getSource() |
|
129 | + { |
|
130 | + $e = $this; |
|
131 | + while ($e->getPrevious()) { |
|
132 | + $e = $e->getPrevious(); |
|
133 | + } |
|
134 | + return basename($e->getFile()) . ':' |
|
135 | + . $e->getLine() . ' at ' |
|
136 | + . $this->getStage() . ' stage'; |
|
137 | + } |
|
138 | 138 | } |