/
Coordinator.class.php
66 lines (48 loc) · 1.74 KB
/
Coordinator.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
Library::import('recess.http.ForwardingResponse');
/**
* Entry into Recess! Framework occurs in the coordinator. It is responsible
* for the flow of control from preprocessing of request data, the serving of a request
* in a controller, and rendering a response to the request through a view.
*
* @author Kris Jordan
* @final
*/
final class Coordinator {
/**
* Recess! Framework Entry Point
* @param Request $request The raw Request.
* @package recess
* @static
*/
public static function main(Request $request, IPolicy $policy, array $apps, RoutingNode $routes, array $plugins = array()) {
static $callDepth = 0;
$callDepth++;
if($callDepth > 2) { echo 'too nested in main'; exit; }
$pluggedPolicy = $policy;
// foreach($plugins as $plugin) {
// $pluggedPolicy = $plugin->decorate($pluggedPolicy);
// }
// try {
$request = $pluggedPolicy->preprocess($request);
// $controller = $pluggedPolicy->getControllerFor($request, $routing);
$controller = $pluggedPolicy->getControllerFor($request, $apps, $routes);
$response = $controller->serve($request);
$view = $pluggedPolicy->getViewFor($response);
if($callDepth > 5) throw new RecessException('Forwarding depth too great.', get_defined_vars());
$view->respondWith($response);
if($response instanceof ForwardingResponse) {
$forwardRequest = new Request();
$forwardRequest->setResource($response->forwardUri);
$forwardRequest->method = Methods::GET;
Coordinator::main($forwardRequest, $policy, $apps, $routes, $plugins);
}
// $pluggedPolicy->end();
// } catch(Exception $e) {
// $plugins->preHandleException($e);
// Diagnostics::handleException($e);
// $plugins->postHandleException($e);
// }
}
}
?>