1 | <?php |
||
21 | class Server { |
||
22 | |||
23 | /** |
||
24 | * RFC 1123 Date-Time Format |
||
25 | */ |
||
26 | const RFC1123_DATE_FORMAT = 'D, d M Y H:i:s T'; |
||
27 | |||
28 | // |
||
29 | // CAS Server Methods |
||
30 | // |
||
31 | |||
32 | /** |
||
33 | * Get the list of routes supported by this CAS server and the callbacks each will invoke. |
||
34 | * |
||
35 | * - `/login` |
||
36 | * - `/logout` |
||
37 | * - `/proxy` |
||
38 | * - `/proxyValidate` |
||
39 | * - `/serviceValidate` |
||
40 | * - `/validate` |
||
41 | * |
||
42 | * @return array Array containing supported routes as keys and their callbacks as values. |
||
43 | * |
||
44 | * @uses \apply_filters() |
||
45 | */ |
||
46 | public function routes() { |
||
69 | |||
70 | /** |
||
71 | * Perform an HTTP redirect. |
||
72 | * |
||
73 | * If the 'allowed_services' contains at least one host, it will always perform a safe |
||
74 | * redirect. |
||
75 | * |
||
76 | * Calling Server::redirect() will _always_ end the request. |
||
77 | * |
||
78 | * @param string $location URI to redirect to. |
||
79 | * @param integer $status HTTP status code (default 302). |
||
80 | * |
||
81 | * @uses \wp_redirect() |
||
82 | * @uses \wp_safe_redirect() |
||
83 | */ |
||
84 | public function redirect( $location, $status = 302 ) { |
||
94 | |||
95 | /** |
||
96 | * Handle a CAS server request for a specific URI. |
||
97 | * |
||
98 | * This method will attempt to set the following HTTP headers to prevent browser caching: |
||
99 | * |
||
100 | * - `Pragma: no-cache` |
||
101 | * - `Cache-Control: no-store` |
||
102 | * - `Expires: <time of request>` |
||
103 | * |
||
104 | * @param string $path CAS request URI. |
||
105 | * |
||
106 | * @return string Request response. |
||
107 | * |
||
108 | * @throws \Cassava\Exception\GeneralException |
||
109 | * |
||
110 | * @global $_SERVER |
||
111 | * |
||
112 | * @uses \apply_filters() |
||
113 | * @uses \do_action() |
||
114 | */ |
||
115 | public function handleRequest( $path ) { |
||
164 | |||
165 | /** |
||
166 | * Dispatch the request for processing by the relevant callback as determined by the routes |
||
167 | * list returned by `Server::routes()`. |
||
168 | * |
||
169 | * @param string $path Requested URI path. |
||
170 | * @return mixed Service response string or WordPress error. |
||
171 | * |
||
172 | * @throws \Cassava\Exception\GeneralException |
||
173 | * @throws \Cassava\Exception\RequestException |
||
174 | * |
||
175 | * @global $_GET |
||
176 | * |
||
177 | * @uses \apply_filters() |
||
178 | * @uses \is_ssl() |
||
179 | * @uses \is_wp_error() |
||
180 | */ |
||
181 | protected function dispatch( $path ) { |
||
245 | |||
246 | /** |
||
247 | * Wraps calls to session_start() to prevent 'headers already sent' errors. |
||
248 | * |
||
249 | * @fixme Do we REALLY need sessions? |
||
250 | */ |
||
251 | public function sessionStart() { |
||
260 | |||
261 | /** |
||
262 | * Wraps calls to session destruction functions. |
||
263 | * |
||
264 | * @fixme Do we REALLY need sessions? |
||
265 | */ |
||
266 | public function sessionDestroy() { |
||
279 | |||
280 | /** |
||
281 | * Sets an HTTP response header. |
||
282 | * |
||
283 | * @param string $key Header key. |
||
284 | * @param string $value Header value. |
||
285 | */ |
||
286 | protected function setResponseHeader( $key, $value ) { |
||
293 | |||
294 | /** |
||
295 | * Set response headers for a CAS version response. |
||
296 | */ |
||
297 | public function setResponseContentType( $type ) { |
||
300 | |||
301 | /** |
||
302 | * Redirects the user to either the standard WordPress authentication page or a custom one |
||
303 | * at a URI returned by the `cas_server_custom_auth_uri` filter. |
||
304 | * |
||
305 | * @param array $args HTTP request parameters received by `/login`. |
||
306 | * |
||
307 | * @uses apply_filters() |
||
308 | * @uses auth_redirect() |
||
309 | */ |
||
310 | public function authRedirect( $args = array() ) { |
||
326 | |||
327 | } |
||
328 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.