mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
[FEATURE] Added custom boot managers
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user