namespace hoplite\http;
+require_once HOPLITE_ROOT . '/base/weak_interface.php';
require_once HOPLITE_ROOT . '/http/request.php';
require_once HOPLITE_ROOT . '/http/response.php';
require_once HOPLITE_ROOT . '/http/response_code.php';
/*! @var OutputFilter */
private $output_filter = NULL;
+ /*! @var WeakInterface<RootControllerDelegate> */
+ private $delegate = NULL;
+
/*!
Creates the controller with the request context information, typicallhy
from the global scope ($GLOBALS), but can be injected for testing.
'_COOKIE' => &$globals['_COOKIE'],
'_SERVER' => &$globals['_SERVER']
);
+ $this->delegate = new \hoplite\base\WeakInterface('hoplite\http\RootControllerDelegate');
}
/*! Accessors */
$this->output_filter = $output_filter;
}
+ /*! Sets the delegate. */
+ public function set_delegate($delegate)
+ {
+ $this->delegate->Bind($delegate);
+ }
+
/*!
Createst the Request and Response that are used throughout the duration of
the execution.
$this->request->url = $url;
$this->request->http_method = $this->request->data['_SERVER']['REQUEST_METHOD'];
+ $this->delegate->OnInitialRequest($this->request);
+
// Dispatch the request to an Action.
$this->RouteRequest($this->request);
*/
public function Stop()
{
+ $this->delegate->WillStop($this->request, $this->response);
$this->output_filter->FilterOutput($this->request, $this->response);
$this->_Exit();
}
*/
public function RouteRequest(Request $request)
{
+ $this->delegate->WillRouteRequest($request, $this->response);
+
$url_map_value = $this->url_map->Evaluate($request);
$action = NULL;
*/
public function InvokeAction(Action $action)
{
+ $this->delegate->WillInvokeAction($action, $this->request, $this->response);
+
$action->FilterRequest($this->request, $this->response);
$action->Invoke($this->request, $this->response);
$action->FilterResponse($this->request, $this->response);
+
+ $this->delegate->DidInvokeAction($action, $this->request, $this->response);
}
/*!
}
}
}
+
+/*!
+ Delegate for the root controller. The controller uses WeakInterface to call
+ these methods, so they're all optional.
+*/
+interface RootControllerDelegate
+{
+ public function OnInitialRequest(Request $request);
+
+ public function WillRouteRequest(Request $request, Response $response);
+
+ public function WillInvokeAction(Action $action, Request $request, Response $response);
+
+ public function DidInvokeAction(Action $action, Request $request, Response $response);
+
+ public function WillStop(Request $request, Response $response);
+}