/** * On kernel response event * * @param FilterResponseEvent $event */ public function onKernelResponse(FilterResponseEvent $event) { // Only master request and 200 OK are processed if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType() && $event->getResponse()->isOk()) { $route = $this->router->match($this->request->getPathInfo()); // Ignore internal route if (0 === stripos($route['_route'], '_')) { return; } $this->session->set('_unifik.last_master_request_uri', $this->request->getUri()); $this->session->set('_unifik.last_master_request_route', $route); } }
/** * Resolve current request and remember the matched route */ public function routeCurrentRequest() { $path = $this->currentRequest->getPathInfo(); $matched = $this->sfRouter->match($path); $this->currentRoute = $matched['_route']; return $matched; }
public function route($url) { try { $context = new RequestContext(); $context->fromRequest($this->_request); $closure = function () { return $this->_container->get('routes'); }; $arrpar = array(); if (!DEVELOPMENT_ENVIRONMENT) { $arrpar['cache_dir'] = ROUTECACHE; } else { \Debug::addRoutes($closure); } $router = new SymfonyRouter(new ClosureLoader(), $closure, $arrpar, $context); $parameters = $router->match($url); $this->_controller = $parameters["controller"]; $this->_method = $parameters["action"]; $this->_route = $parameters["_route"]; unset($parameters["controller"]); unset($parameters["action"]); unset($parameters["_route"]); $this->_args = $parameters; } catch (ResourceNotFoundException $e) { $this->_route = ""; } catch (\Symfony\Component\Routing\Exception\MethodNotAllowedException $ema) { $this->_route = ""; throw new \GL\Core\Exception\MethodNotAllowedException(); } return $this->_route != ""; }
private function matchRoute($routePath) { $locator = new FileLocator(array($this->container->getParameter('configDir'))); $router = new Router(new YamlFileLoader($locator), 'routes.yml', array('cache_dir' => null), $this->requestContext); $parameters = $router->match($routePath); return $parameters; }
public function match($pathinfo) { $match = parent::match($pathinfo); // injects the route into the route collection, so Silex will keep its behavior $route = $this->getRouteFromMatch($match, $pathinfo); $this->routes->add($match['_route'], $route); return $match; }
/** * @param ApiDoc $annotation * @param array $annotations * @param Route $route * @param \ReflectionMethod $method */ public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { if (!($resource = $this->getResource($route))) { return; } $context = new RequestContext('', $resource->getActions()->getActionForRoute($route)->getMethods()[0]); $this->router->setContext($context); $routeName = $this->router->match($route->getPath())['_route']; $section = $this->getSection($routeName, $resource); foreach ($annotations as $annot) { if ($annot instanceof GenerateApiDoc) { $annotation->setSection($section); if ($this->returnsEntity($route)) { $this->setOutput($annotation, $resource); } if ($this->expectsInput($route)) { if ($resource->getFormTypeClass() == DynamicFormType::class) { $entityClass = $resource->getEntityClass(); $handler = new DynamicFormSubscriber($this->em, new $entityClass()); foreach ($handler->getFields() as $field) { $annotation->addParameter($field, ['dataType' => 'string', 'required' => false]); } } else { $this->setInput($annotation, $resource); } } if ($roles = $route->getDefault('_roles')) { $annotation->setAuthentication(true); $annotation->setAuthenticationRoles($roles); } $annotation->setDescription($this->getDescription($resource, $route)); $annotation->setDocumentation($this->getDescription($resource, $route)); if ($resource->getActions()->getActionForRoute($route) instanceof Index) { $this->addFilter($annotation, $resource); $this->addPagination($annotation, $resource); } } } }
$context = new RequestContext(); $context->fromRequest(Request::createFromGlobals()); $matcher = new UrlMatcher($collection, $context); try { $attributes = $matcher->match($request->getPathInfo()); print_r($attributes); } catch (Routing\Exception\ResourceNotFoundException $e) { $response = new Response('Not Found', 404); $response->send(); } catch (Exception $e) { $response = new Response('An error occurred', 500); $response->send(); } */ $locator = new FileLocator(array(__DIR__ . '/test/')); $request = Request::createFromGlobals(); $requestContext = new RequestContext($request); $router = new Router(new YamlFileLoader($locator), 'route.yml', array('cache_dir' => __DIR__ . '/test/cache/'), $requestContext); try { $attributes = $router->match($request->getPathInfo()); print_r($attributes); } catch (Routing\Exception\ResourceNotFoundException $e) { $response = new Response('Not Found', 404); $response->send(); } catch (Exception $e) { //print_r($e); $response = new Response('An error occurred', 500); $response->send(); }
public function route($uri = false) { if (!$uri) { if (empty($_SERVER['REDIRECT_URL'])) { if (stristr($_SERVER['REQUEST_URI'], '?') !== false) { $uri = stristr($_SERVER['REQUEST_URI'], '?', true); } else { $uri = $_SERVER['REQUEST_URI']; } } else { $uri = $_SERVER['REDIRECT_URL']; } } $context = new RequestContext($uri); $locator = new FileLocator(array(dirname(__FILE__) . '/../conf')); $router = new Router(new PhpFileLoader($locator), 'routes.php', array('cache_dir' => null), $context); if (!$uri) { $uri = $this->httpRequest->getPathInfo(); } $this->route = $router->match($uri); $this->controller = new $this->route['class']($this); if (DEBUG_BAR) { $this->debugbar->addCollector(new ConfigCollector($this->config)); $debugbarRenderer = $this->debugbar->getJavascriptRenderer(); $this->debugbar["messages"]->addMessage("Debug Bar enabled"); $this->controller->setData('debugbarRenderer', $debugbarRenderer); } //set action to index is its not set if (empty($this->route['action'])) { $this->route['action'] = $this->route['_route'] == '/' ? "index" : $this->route['_route']; } $action = $this->route['action']; if (!method_exists($this->controller, $action)) { throw new Exception('Method Not found'); } $this->controller->{$action}(); }