Added support for arguments in new Routes

This commit is contained in:
Marcin Kurczewski 2014-11-20 09:43:48 +01:00
parent 2a7ca79b2d
commit 7c182f57a0
2 changed files with 24 additions and 1 deletions

View file

@ -19,8 +19,19 @@ final class Route
if (!preg_match($this->regex, $query, $matches))
return false;
$routeArguments = $this->getRouteArguments($matches);
$func = $this->route;
$output = $func(...array_values($routeArguments));
if (is_array($this->route) && $this->route[1] === 'work')
{
foreach ($matches as $key => $value)
$this->route[0]->setArgument($key, $value);
$output = $func();
}
else
{
$output = $func(...array_values($routeArguments));
}
return true;
}

View file

@ -3,9 +3,21 @@ namespace Szurubooru\Routes;
abstract class AbstractRoute
{
protected $arguments = [];
public abstract function getMethods();
public abstract function getUrl();
public abstract function work();
public function setArgument($argName, $argValue)
{
$this->arguments[$argName] = $argValue;
}
protected function getArgument($argName)
{
return $this->arguments[$argName];
}
}