diff --git a/Autoloader.php b/Autoloader.php index 9ee328ee4..d05b6c2d0 100644 --- a/Autoloader.php +++ b/Autoloader.php @@ -81,7 +81,7 @@ final class Autoloader $class = \str_replace(['_', '\\'], '/', $class); foreach (self::$paths as $path) { - if (file_exists($file = $path . $class . '.php')) { + if (\file_exists($file = $path . $class . '.php')) { include_once $file; return; @@ -106,7 +106,7 @@ final class Autoloader $class = \str_replace(['_', '\\'], '/', $class); foreach (self::$paths as $path) { - if (file_exists($file = $path . $class . '.php')) { + if (\file_exists($file = $path . $class . '.php')) { return true; } } diff --git a/Router/Router.php b/Router/Router.php index 4200e5230..5d71c7dba 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -60,7 +60,7 @@ final class Router * Add route. * * @param string $route Route regex - * @param mixed $destination Destination e.g. Module:function & verb + * @param mixed $destination Destination e.g. Module:function string or callback * @param int $verb Request verb * * @return void @@ -91,22 +91,22 @@ final class Router * * @since 1.0.0 */ - public function route($request, int $verb = RouteVerb::GET) : array + public function route(string $request, int $verb = RouteVerb::GET, string $app = '', string $orgId = '', $account = null) : array { - if ($request instanceof RequestAbstract) { - $uri = $request->getUri()->getRoute(); - $verb = $request->getRouteVerb(); - } elseif (\is_string($request)) { - $uri = $request; - } else { - throw new \InvalidArgumentException(); - } - $bound = []; foreach ($this->routes as $route => $destination) { foreach ($destination as $d) { - if ($this->match($route, $d['verb'], $uri, $verb)) { - $bound[] = ['dest' => $d['dest']]; + if ($this->match($route, $d['verb'], $request, $verb)) { + if (!isset($d['permission']) + || !isset($account) + || (isset($d['permission']) + && isset($account) + && $account->hasPermission($d['permission']['type'], $orgId, $app, $d['permission']['module'], $d['permission']['state'])) + ) { + $bound[] = ['dest' => $d['dest']]; + } else { + array_merge($bound, $this->route('/' . $app . '/e403', $verb)); + } } } } diff --git a/tests/Router/RouterTest.php b/tests/Router/RouterTest.php index 5541dfcdd..ab2f41333 100644 --- a/tests/Router/RouterTest.php +++ b/tests/Router/RouterTest.php @@ -75,13 +75,4 @@ class RouterTest extends \PHPUnit\Framework\TestCase $router->route('http://test.com/backends/admin/settings/general/something?test', RouteVerb::GET) ); } - - /** - * @expectedException \InvalidArgumentException - */ - public function testInvalidRequestType() - { - $router = new Router(); - $router->route([]); - } }