当前位置: 首页>>代码示例>>PHP>>正文


PHP UrlMatcher::matchRequest方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\Matcher\UrlMatcher::matchRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlMatcher::matchRequest方法的具体用法?PHP UrlMatcher::matchRequest怎么用?PHP UrlMatcher::matchRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\Matcher\UrlMatcher的用法示例。


在下文中一共展示了UrlMatcher::matchRequest方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: match

 public function match($urlOrRequest = null)
 {
     $request = $this->makeRequest($urlOrRequest);
     $matcher = new UrlMatcher($this->getRoutes(), $this->context);
     $params = $matcher->matchRequest($request);
     return $this->handler->handle($params, $request);
 }
开发者ID:allmarkedup,项目名称:super-sharp-router,代码行数:7,代码来源:Router.php

示例2: getController

 /**
  * Returns the Controller instance associated with a Request.
  *
  * As several resolvers can exist for a single application, a resolver must
  * return false when it is not able to determine the controller.
  *
  * The resolver must only throw an exception when it should be able to load
  * controller but cannot because of some errors made by the developer.
  *
  * @param Request $request A Request instance
  *
  * @return callable|false A PHP callable representing the Controller,
  *                        or false if this resolver is not able to determine the controller
  *
  * @throws \LogicException If the controller can't be found
  *
  * @api
  */
 public function getController(Request $request)
 {
     $route = $this->urlMatcher->matchRequest($request);
     $controllerClass = sprintf("\\DG\\SymfonyCert\\Controller\\%sController", ucfirst($route['_controller']));
     $controller = new $controllerClass($this->container);
     $attributes = [];
     foreach ($route as $key => $value) {
         if (strpos($key, '_') !== 0) {
             $attributes[$key] = $value;
         } else {
             $request->attributes->set($key, $value);
         }
         if ($key === '_locale') {
             $request->getSession()->set('locale', $value);
         }
     }
     $request->attributes->set('data', $attributes);
     return [$controller, $route['_action'] . 'Action'];
 }
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:37,代码来源:CustomControllerResolver.php

示例3: work

 /**
  * @return RouteParametersItem
  */
 public function work()
 {
     RouteCache::work(self::$routesFile);
     $this->addRoutesToRouteCollection();
     $context = new RequestContext();
     $context->fromRequest(Request::request());
     $matcher = new UrlMatcher($this->routeCollection, $context);
     $parameters = $matcher->matchRequest(Request::request());
     return new RouteParametersItem($parameters);
 }
开发者ID:impress-php,项目名称:framework,代码行数:13,代码来源:RouteMatch.php

示例4: matchRoute

 public final function matchRoute(\bolt\browser\route $route, \bolt\browser\request $req)
 {
     $collection = b::browser('route\\collection\\create', [$route]);
     $match = new UrlMatcher($collection, $req->getContext());
     // we're going to try and match our request
     // if not we fall back to error
     try {
         return $match->matchRequest($req);
     } catch (ResourceNotFoundException $e) {
         return false;
     }
 }
开发者ID:boltphp,项目名称:core,代码行数:12,代码来源:middleware.php

示例5: findAction

 /**
  * @param Request $request
  * @return Action|null
  */
 public function findAction(Request $request)
 {
     $context = new RequestContext();
     $context->fromRequest($request->getInternalRequest());
     $matcher = new UrlMatcher($this->_routes, $context);
     try {
         $params = $matcher->matchRequest($request->getInternalRequest());
     } catch (\RuntimeException $exception) {
         return null;
     }
     $controllerName = $params['_controllerName'];
     $methodName = $params['_methodName'];
     unset($params['_controllerName']);
     unset($params['_methodName']);
     unset($params['_route']);
     return new Action($controllerName, $methodName, $params);
 }
开发者ID:codespot,项目名称:wrestler,代码行数:21,代码来源:Router.php

示例6:

 function it_should_capture_any_kind_of_error_as_internal_server_error(UrlMatcher $matcher, AnnotExecutor $executor, Request $request, Response $response)
 {
     $matcher->matchRequest(Argument::Any())->willThrow("Exception");
     $response->setStatusCode(500)->shouldBeCalled();
     $this->run($request, $response)->shouldBe($response);
 }
开发者ID:wdalmut,项目名称:frankie,代码行数:6,代码来源:AppSpec.php

示例7: resolve

 /**
  * Resolves a route and its parameters based on the path in the request.
  * @return array An array of parameters.
  */
 public function resolve()
 {
     $currentRoute = $this->_request->server->get('REQUEST_URI');
     $context = new RequestContext();
     $context->fromRequest($this->_request);
     $matcher = new UrlMatcher($this->_routeCollection, $context);
     try {
         $parameters = $matcher->matchRequest($this->_request);
     } catch (Exception $e) {
         if ($this->_defaultController) {
             return ['controller' => $this->_defaultController, '_route' => 'default'];
         }
         throw new Exception('Could not find route "' . $currentRoute . '"');
     }
     return $parameters;
 }
开发者ID:ua1-labs,项目名称:ulfberht-application,代码行数:20,代码来源:router.php

示例8: array

 * a method in our controller (sometimes called an action). This might seem
 * unnecessary, but routers can be really helpful as your site grows.
 * 
 * Check out more information here:
 * 
 * http://symfony.com/doc/current/components/routing/introduction.html
 * 
 * We're going to start off with two routes for our two different types of page.
 */
$routes = array('index' => new Route('/', array('_controller' => $siteController, '_method' => 'indexPage')), 'general' => new Route('/hello/{name}', array('_controller' => $siteController, '_method' => 'generalPage')));
// Add our routes to a collection
$routeCollection = new RouteCollection();
foreach ($routes as $routeName => $route) {
    $routeCollection->add($routeName, $route);
}
/*
 * Match the request we generated earlier to a route. UrlMatcher::matchRequest
 * will throw an exception if it cannot match a request.
 *
 * We need to catch this exception and turn it into a not found response.
 */
$matcher = new UrlMatcher($routeCollection, new RequestContext('/'));
try {
    $result = $matcher->matchRequest($request);
    // Execute our controller and get the response
    $response = $result['_controller']->{$result}['_method']($result, $request);
} catch (ResourceNotFoundException $exception) {
    $response = new Response('Page not found', 404);
}
// Send the response. Under the hood this uses a combination of 'echo' and 'header()'
$response->send();
开发者ID:AndrewCarterUK,项目名称:SimpleSite,代码行数:31,代码来源:index.php


注:本文中的Symfony\Component\Routing\Matcher\UrlMatcher::matchRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。