Added support for arguments in new Routes
This commit is contained in:
parent
2a7ca79b2d
commit
7c182f57a0
2 changed files with 24 additions and 1 deletions
|
@ -19,8 +19,19 @@ final class Route
|
|||
if (!preg_match($this->regex, $query, $matches))
|
||||
return false;
|
||||
$routeArguments = $this->getRouteArguments($matches);
|
||||
|
||||
$func = $this->route;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue