mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-24 09:42:43 +01:00
Add late callback instantiation in Router
with Class@method
syntax
This commit is contained in:
parent
1338b5b88a
commit
40cb2ff644
@ -86,9 +86,6 @@ class Router
|
||||
if (!in_array($method, $this->methods)) {
|
||||
throw new LogicException('Invalid HTTP method "' . $method . '"');
|
||||
}
|
||||
if (!is_null($callback) && !is_callable($callback)) {
|
||||
throw new LogicException('Invalid callback ' . implode('::', (array) $callback));
|
||||
}
|
||||
if (is_array($route)) {
|
||||
foreach ($route as $r) {
|
||||
$this->add($type, $method, $r, $callback);
|
||||
@ -108,6 +105,14 @@ class Router
|
||||
foreach ($this->routes as $route) {
|
||||
if (HTTPRequest::type() === $route['type'] && HTTPRequest::method() === $route['method'] && $this->match($route['route'])) {
|
||||
$this->dispatched = true;
|
||||
// Parse Class@method callback syntax
|
||||
if (is_string($route['callback']) && strpos($route['callback'], '@') !== false) {
|
||||
list($class, $method) = explode('@', $route['callback']);
|
||||
$route['callback'] = array(new $class(), $method);
|
||||
}
|
||||
if (!is_callable($route['callback'])) {
|
||||
throw new LogicException('Invalid callback for ' . $route['route'] . ' route');
|
||||
}
|
||||
return $route['callback']($this->params);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user