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


PHP RouteCollection::get方法代碼示例

本文整理匯總了PHP中Symfony\Component\Routing\RouteCollection::get方法的典型用法代碼示例。如果您正苦於以下問題:PHP RouteCollection::get方法的具體用法?PHP RouteCollection::get怎麽用?PHP RouteCollection::get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Routing\RouteCollection的用法示例。


在下文中一共展示了RouteCollection::get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onKernelView

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $e
  */
 public function onKernelView(GetResponseForControllerResultEvent $e)
 {
     $queryset = $e->getControllerResult();
     $routeName = $e->getRequest()->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $interface = 'SDispatcher\\Common\\PaginatorInterface';
     $paginatorClass = $route->getOption(RouteOptions::PAGINATOR_CLASS);
     if (!$paginatorClass || !is_subclass_of($paginatorClass, $interface)) {
         return;
     }
     try {
         /* @var \SDispatcher\Common\PaginatorInterface $paginator */
         $paginator = new $paginatorClass();
         if (!$paginator->supports($queryset)) {
             return;
         }
         list($headers, $data) = $paginator->paginate($e->getRequest(), $queryset, 0, $route->getOption(RouteOptions::PAGE_LIMIT), $route->getOption(RouteOptions::PAGINATED_META_CONTAINER_NAME), $route->getOption(RouteOptions::PAGINATED_DATA_CONTAINER_NAME));
     } catch (\Exception $ex) {
         list($headers, $data) = array(array(), array());
     }
     $response = new DataResponse($data);
     $response->headers->add($headers);
     $e->setResponse($response);
 }
開發者ID:bcen,項目名稱:silex-dispatcher,代碼行數:30,代碼來源:PaginationListener.php

示例2: alterRoutes

  /**
   * New and improved hook_menu_alter().
   */
  public function alterRoutes(RouteCollection $collection) {
    // admin/structure/taxonomy
    if ($route = $collection->get('entity.taxonomy_vocabulary.collection')) {
      $route->setRequirements(array(
        '_custom_access' => '\taxonomy_access_fix_route_access',
      ));
      $route->setOption('op', 'index');
    }

    // admin/structure/taxonomy/%vocabulary
    if ($route = $collection->get('entity.taxonomy_vocabulary.overview_form')) {
      $route->setRequirements(array(
        '_custom_access' => '\taxonomy_access_fix_route_access',
      ));
      $route->setOption('op', 'list terms');
    }

    // admin/structure/taxonomy/%vocabulary/add
    if ($route = $collection->get('entity.taxonomy_term.add_form')) {
      $route->setRequirements(array(
        '_custom_access' => '\taxonomy_access_fix_route_access',
      ));
      $route->setOption('op', 'add terms');
    }
  }
開發者ID:eloiv,項目名稱:botafoc.cat,代碼行數:28,代碼來源:RouteSubscriber.php

示例3: alterRoutes

 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
         // Try to get the route from the current collection.
         $link_template = $entity_type->getLinkTemplate('canonical');
         if (strpos($link_template, '/') !== FALSE) {
             $base_path = '/' . $link_template;
         } else {
             if (!($entity_route = $collection->get("entity.{$entity_type_id}.canonical"))) {
                 continue;
             }
             $base_path = $entity_route->getPath();
         }
         // Inherit admin route status from edit route, if exists.
         $is_admin = FALSE;
         $route_name = "entity.{$entity_type_id}.edit_form";
         if ($edit_route = $collection->get($route_name)) {
             $is_admin = (bool) $edit_route->getOption('_admin_route');
         }
         $path = $base_path . '/translations';
         $route = new Route($path, array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::overview', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_overview' => $entity_type_id), array('parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $route_name = "entity.{$entity_type_id}.content_translation_overview";
         $collection->add($route_name, $route);
         $route = new Route($path . '/add/{source}/{target}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::add', 'source' => NULL, 'target' => NULL, '_title' => 'Add', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_manage' => 'create'), array('parameters' => array('source' => array('type' => 'language'), 'target' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_add", $route);
         $route = new Route($path . '/edit/{language}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::edit', 'language' => NULL, '_title' => 'Edit', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'update'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_edit", $route);
         $route = new Route($path . '/delete/{language}', array('_entity_form' => $entity_type_id . '.content_translation_deletion', 'language' => NULL, '_title' => 'Delete', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'delete'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_delete", $route);
     }
 }
開發者ID:neetumorwani,項目名稱:blogging,代碼行數:34,代碼來源:ContentTranslationRouteSubscriber.php

示例4: getRouteByName

 /**
  * @inheritdoc
  */
 public function getRouteByName($name, $params = [])
 {
     if ($route = $this->routes->get($name)) {
         return $route;
     }
     return null;
 }
開發者ID:harentius,項目名稱:blog-bundle,代碼行數:10,代碼來源:RouteProvider.php

示例5: getIndexControllerWithSets

 private function getIndexControllerWithSets($cachePath = null)
 {
     $extractor = $this->getExtractor(null, '', $cachePath);
     $extractor->expects($this->any())->method('getRoutes')->will($this->returnCallback(function (array $sets = array()) {
         $routes = new RouteCollection();
         $routesDefinition = array('no_set' => array(), 'set1' => array('set1'), 'set1set2' => array('set1', 'set2'), 'set3' => array('set3'));
         foreach ($routesDefinition as $name => $routeSets) {
             $routes->add($name, new Route('/' . $name, array(), array(), array('expose_sets' => $routeSets)));
         }
         $routesSet1 = new RouteCollection();
         $routesSet1->add('set1', $routes->get('set1'));
         $routesSet1->add('set1set2', $routes->get('set1set2'));
         $routesSet2Set3 = new RouteCollection();
         $routesSet2Set3->add('set1set2', $routes->get('set1set2'));
         $routesSet2Set3->add('set3', $routes->get('set3'));
         if ($sets == array('set1')) {
             return $routesSet1;
         } elseif ($sets == array('set2', 'set3')) {
             return $routesSet2Set3;
         }
         throw new \InvalidArgumentException(sprintf('Theses sets are not configured : %s', join(', ', $sets)));
     }));
     $controller = new Controller($this->getSerializer(), $extractor);
     return $controller;
 }
開發者ID:CoderRoman,項目名稱:FOSJsRoutingBundle,代碼行數:25,代碼來源:ControllerTest.php

示例6: doKernelResponse

 protected function doKernelResponse(Request $request, Response $response)
 {
     if (!$response instanceof DataResponse) {
         return;
     }
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $acceptedFormat = $route->getOption(RouteOptions::ACCEPTED_FORMAT);
     if (!$acceptedFormat) {
         $response->setContent('');
         $response->setStatusCode(406);
     }
     if ($this->encoder->supportsEncoding($acceptedFormat) && $acceptedFormat === 'json') {
         $contentType = $request->getMimeType($acceptedFormat);
         $jsonResponse = new JsonResponse($response->getContent());
         $response->setContent($jsonResponse->getContent());
         $response->headers->set('Content-Type', $contentType);
     } elseif ($this->encoder->supportsEncoding($acceptedFormat)) {
         $contentType = $request->getMimeType($acceptedFormat);
         $content = $this->encoder->encode($response->getContent(), $acceptedFormat);
         $response->setContent($content);
         $response->headers->set('Content-Type', $contentType);
     }
 }
開發者ID:bcen,項目名稱:silex-dispatcher,代碼行數:27,代碼來源:Serializer.php

示例7: onKernelController

 /**
  * Handler Kernel Controller events
  *
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     $route = $this->routes->get($request->attributes->get('_route'));
     if ($route && $route->hasContent()) {
         $this->populateContent($route, $request);
     }
 }
開發者ID:phpillip,項目名稱:phpillip,代碼行數:13,代碼來源:ContentConverterListener.php

示例8: alterRoutes

 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection) {
   if ($route = $collection->get('node.revision_revert_confirm')) {
     $route->setDefault('_form', '\Drupal\revision_ui\Form\NodeRevisionRevertForm');
   }
   if ($route = $collection->get('node.revision_revert_translation_confirm')) {
     $route->setDefault('_form', '\Drupal\revision_ui\Form\NodeRevisionRevertTranslationForm');
   }
 }
開發者ID:rmiessau,項目名稱:sftest,代碼行數:11,代碼來源:RouteSubscriber.php

示例9: getRoutesByNames

 /**
  * Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRoutesByName().
  */
 public function getRoutesByNames($names)
 {
     $routes = array();
     foreach ($names as $name) {
         $routes[] = $this->routes->get($name);
     }
     return $routes;
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:11,代碼來源:MockRouteProvider.php

示例10: testAddPrefix

 public function testAddPrefix()
 {
     $collection = new RouteCollection();
     $collection->add('foo', $foo = new Route('/foo'));
     $collection->add('bar', $bar = new Route('/bar'));
     $collection->addPrefix('/admin');
     $this->assertEquals('/admin/foo', $collection->get('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
     $this->assertEquals('/admin/bar', $collection->get('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
 }
開發者ID:notbrain,項目名稱:symfony,代碼行數:9,代碼來源:RouteCollectionTest.php

示例11: onKernelReponse

 /**
  * Handler Kernel Response events
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelReponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $route = $this->routes->get($request->attributes->get('_route'));
     if ($route && $route->hasContent() && !$response->headers->has('Last-Modified')) {
         $this->setLastModifiedHeader($route, $request, $response);
     }
 }
開發者ID:phpillip,項目名稱:phpillip,代碼行數:14,代碼來源:LastModifiedListener.php

示例12: onKernelReponse

 /**
  * Handler Kernel Response events
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelReponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $route = $this->routes->get($request->attributes->get('_route'));
     if ($route && $route->isMapped()) {
         $url = $request->attributes->get('_canonical');
         $lastModified = new DateTime($response->headers->get('Last-Modified'));
         $this->sitemap->add($url, $lastModified);
     }
 }
開發者ID:phpillip,項目名稱:phpillip,代碼行數:16,代碼來源:SitemapListener.php

示例13: alterRoutes

 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     if ($collection->get('tmgmt.admin_tmgmt')) {
         $route = $collection->get('tmgmt.admin_tmgmt');
         $route->addRequirements(['_permission' => $collection->get('tmgmt.admin_tmgmt')->getRequirement('_permission') . '+administer translation tasks+provide translation services']);
     }
     foreach ($collection->all() as $route) {
         if (strpos($route->getPath(), '/translate') === 0 && $this->configFactory->get('tmgmt_local.settings')->get('use_admin_theme') || strpos($route->getPath(), '/manage-translate') === 0) {
             $route->setOption('_admin_route', TRUE);
         }
     }
 }
開發者ID:andrewl,項目名稱:andrewlnet,代碼行數:15,代碼來源:RouteSubscriber.php

示例14: alterRoutes

 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     // Change path '/user/login' to '/login'.
     if ($route = $collection->get('user.login')) {
         $route->setPath('/login');
     }
     // Always deny access to '/user/logout'.
     // Note that the second parameter of setRequirement() is a string.
     if ($route = $collection->get('user.logout')) {
         $route->setRequirement('_access', 'FALSE');
     }
 }
開發者ID:krknth,項目名稱:d8p,代碼行數:15,代碼來源:RouteSubscriber.php

示例15: alterRoutes

 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     // Change path '/user/login' to '/login'.
     if ($route = $collection->get('sociallogin.settings_form')) {
         $route->setPath('admin/config/people/userregistration');
         $defaults = $route->getDefaults();
         $defaults['_title'] = "User Registration settings";
         $route->setDefaults($defaults);
     }
     if ($route = $collection->get('advanced.settings_form')) {
         $route->setPath('admin/config/people/userregistration/advanced');
     }
 }
開發者ID:LoginRadius,項目名稱:drupal-identity-module,代碼行數:16,代碼來源:RouteSubscriber.php


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