本文整理汇总了PHP中Symfony\Component\Routing\Router::match方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::match方法的具体用法?PHP Router::match怎么用?PHP Router::match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Router
的用法示例。
在下文中一共展示了Router::match方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: routeCurrentRequest
/**
* 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;
}
示例2: onKernelResponse
/**
* 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);
}
}
示例3: route
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 != "";
}
示例4: matchRoute
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;
}
示例5: match
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;
}
示例6: handle
/**
* @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);
}
}
}
}
示例7: RequestContext
$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();
}
示例8: route
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}();
}