[FEATURE] Added custom boot managers

This commit is contained in:
Simon Sessingø
2016-03-19 16:14:36 +01:00
parent 5483ffe458
commit b29f2ce37d
7 changed files with 131 additions and 42 deletions
+34 -3
View File
@@ -16,9 +16,9 @@ class RouterBase {
protected $controllerUrlMap;
protected $backStack;
protected $defaultNamespace;
protected $bootManagers;
protected $baseCsrfVerifier;
// TODO: make interface for controller routers, so they can be easily detected
// TODO: clean up - cut some of the methods down to smaller pieces
public function __construct() {
@@ -26,7 +26,8 @@ class RouterBase {
$this->backStack = array();
$this->controllerUrlMap = array();
$this->baseCsrfVerifier = new BaseCsrfVerifier();
$this->request = Request::getInstance();
$this->request = new Request();
$this->bootManagers = array();
$csrf = new CsrfToken();
$token = ($csrf->hasToken()) ? $csrf->getToken() : $csrf->generateToken();
@@ -106,6 +107,18 @@ class RouterBase {
public function routeRequest() {
// Initialize boot-managers
if(count($this->bootManagers)) {
/* @var $manager RouterBootManager */
foreach($this->bootManagers as $manager) {
$this->request = $manager->boot($this->request);
if(!($this->request instanceof Request)) {
throw new RouterException('Custom router bootmanager "'. get_class($manager) .'" must return instance of Request.');
}
}
}
// Verify csrf token for request
if($this->baseCsrfVerifier !== null) {
/* @var $csrfVerifier BaseCsrfVerifier */
@@ -168,6 +181,24 @@ class RouterBase {
$this->defaultNamespace = $defaultNamespace;
}
/**
* @return array
*/
public function getBootManagers() {
return $this->bootManagers;
}
/**
* @param array $bootManagers
*/
public function setBootManagers(array $bootManagers) {
$this->bootManagers = $bootManagers;
}
public function addBootManager(RouterBootManager $bootManager) {
$this->bootManagers[] = $bootManager;
}
/**
* @return RouterEntry
*/