當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Router::match方法代碼示例

本文整理匯總了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;
 }
開發者ID:BGCX067,項目名稱:fajr-git,代碼行數:10,代碼來源:Router.php

示例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);
     }
 }
開發者ID:pmdc,項目名稱:UnifikSystemBundle,代碼行數:18,代碼來源:ResponseListener.php

示例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 != "";
 }
開發者ID:kletellier,項目名稱:mvc,代碼行數:31,代碼來源:Router.php

示例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;
 }
開發者ID:pascal-c,項目名稱:groupfony-framework,代碼行數:7,代碼來源:Routing.php

示例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;
 }
開發者ID:joserobleda,項目名稱:silex-symfony-router,代碼行數:8,代碼來源:Router.php

示例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);
             }
         }
     }
 }
開發者ID:bitecodes,項目名稱:rest-api-generator-bundle,代碼行數:45,代碼來源:GenerateApiDocHandler.php

示例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();
}
開發者ID:lokitold,項目名稱:symfony16,代碼行數:30,代碼來源:test.php

示例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}();
 }
開發者ID:ligerzero459,項目名稱:block-explorer,代碼行數:37,代碼來源:Bootstrap.php


注:本文中的Symfony\Component\Routing\Router::match方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。