當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。