|
|
<?php |
|
|
|
|
|
namespace Kanboard\Core\Http; |
|
|
|
|
|
use Kanboard\Core\Base; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Router extends Base |
|
|
{ |
|
|
const DEFAULT_CONTROLLER = 'DashboardController'; |
|
|
const DEFAULT_METHOD = 'show'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private $currentPluginName = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private $currentControllerName = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private $currentActionName = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getPlugin() |
|
|
{ |
|
|
return $this->currentPluginName; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getController() |
|
|
{ |
|
|
return $this->currentControllerName; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getAction() |
|
|
{ |
|
|
return $this->currentActionName; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getPath() |
|
|
{ |
|
|
$path = substr($this->request->getUri(), strlen($this->helper->url->dir())); |
|
|
|
|
|
if ($this->request->getQueryString() !== '') { |
|
|
$path = substr($path, 0, - strlen($this->request->getQueryString()) - 1); |
|
|
} |
|
|
|
|
|
if ($path !== '' && $path[0] === '/') { |
|
|
$path = substr($path, 1); |
|
|
} |
|
|
|
|
|
return $path; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function dispatch() |
|
|
{ |
|
|
$controller = $this->request->getStringParam('controller'); |
|
|
$action = $this->request->getStringParam('action'); |
|
|
$plugin = $this->request->getStringParam('plugin'); |
|
|
|
|
|
if ($controller === '') { |
|
|
$route = $this->route->findRoute($this->getPath()); |
|
|
$controller = $route['controller']; |
|
|
$action = $route['action']; |
|
|
$plugin = $route['plugin']; |
|
|
} |
|
|
|
|
|
$this->currentControllerName = ucfirst($this->sanitize($controller, self::DEFAULT_CONTROLLER)); |
|
|
$this->currentActionName = $this->sanitize($action, self::DEFAULT_METHOD); |
|
|
$this->currentPluginName = ucfirst($this->sanitize($plugin)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function sanitize($value, $default = '') |
|
|
{ |
|
|
return preg_match('/^[a-zA-Z_0-9]+$/', $value) ? $value : $default; |
|
|
} |
|
|
} |
|
|
|