/** * Build request * * @param string $originalUri Original URI * @param string $requestUri Request URI * @param string $requestMethod Method * * @return mixed */ private function buildRequest($originalUri, $requestUri, $requestMethod) { $uri = preg_replace(array('#^' . BASE_URI . '#', '/\\?.*$/', '/[\\/]?$/'), '', $requestUri); foreach ($this->getModules() as $module) { foreach ($module->getRoutes() as $route) { if ($route->getRequestMethod() === $requestMethod) { foreach ($route->getUrls() as $url) { $checkUri = strtolower(!empty($uri) ? $uri : '/'); if (preg_match('#^' . $url . '$#i', $checkUri, $matches) && $checkUri !== '/' || strtolower($url) === $checkUri) { $request = new Request(); $request->setRoute($route)->setRouteUrl($url)->setUrl($originalUri)->setTheme(self::getTheme()); // If we matched a regular expression set named groups if ($matches) { foreach ($matches as $key => $value) { if (is_string($key)) { $request->setParam($key, $value); } } } $exp = '/(\\/?[^\\/]*){1,2}/'; if (preg_match_all($exp, preg_replace('/^' . str_replace('/', '\\/', $url) . '/', '', $originalUri), $matches)) { foreach ($matches[0] as $kvp) { list($key, $value) = array_pad(explode('/', preg_replace('/^\\//', '', $kvp), 2), 2, null); if (!empty($key)) { $request->setParam($key, $value); } } } return $request; } } } } } $nextUri = preg_replace('/\\/[^\\/]+$/', '', $requestUri); if (!empty($nextUri)) { return $this->buildRequest($originalUri, $nextUri, $requestMethod); } return null; }
public function hasAccess(Request $request) { $acls = $request->getRoute()->getAcls(); $roles = self::getRoles(); if (!empty($acls)) { foreach ($acls as $acl) { if (in_array($acl, $roles)) { return true; } } return false; } return true; }