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


PHP RouteCollection::all方法代码示例

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


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

示例1: testGetRouteCollectionWithRoutes

 public function testGetRouteCollectionWithRoutes()
 {
     $routes = new RouteCollection();
     $controllers = new ControllerCollection($routes);
     $controllers->add(new Controller(new Route('/foo')));
     $controllers->add(new Controller(new Route('/bar')));
     $this->assertEquals(0, count($routes->all()));
     $controllers->flush();
     $this->assertEquals(2, count($routes->all()));
 }
开发者ID:nooks,项目名称:Silex,代码行数:10,代码来源:ControllerCollectionTest.php

示例2: addCollection

 public function addCollection(RouteCollection $collection)
 {
     foreach ($collection->all() as $name => $route) {
         $this->add($name, $route);
     }
     // remove all the routes so that we have an empty collection when calling parent method
     // and we are not re-adding the routes again
     $collection->remove(array_keys($collection->all()));
     // call parent method with empty collection to merge the collection's resources
     parent::addCollection($collection);
 }
开发者ID:lschricke,项目名称:symfony-strict-route-collection,代码行数:11,代码来源:SymfonyStrictRouteCollection.php

示例3: match

 /**
  * {@inheritdoc}
  */
 public function match($theClass, $theMethod)
 {
     $routes = $this->routes->all();
     foreach ($routes as $name => $route) {
         $controller = $route->getDefault('_controller');
         if (false !== strpos($controller, "::")) {
             list($class, $method) = explode('::', $controller, 2);
             if ($class === $theClass && $method === $theMethod) {
                 return array($name, $route);
                 return array('name' => $name, 'route' => $route);
             }
         }
     }
     throw new ResourceNotFoundException();
 }
开发者ID:stanlemon,项目名称:crud-bundle,代码行数:18,代码来源:ControllerMatcher.php

示例4: filter

 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     $method = $request->getMethod();
     $all_supported_methods = [];
     foreach ($collection->all() as $name => $route) {
         $supported_methods = $route->getMethods();
         // A route not restricted to specific methods allows any method. If this
         // is the case, we'll also have at least one route left in the collection,
         // hence we don't need to calculate the set of all supported methods.
         if (empty($supported_methods)) {
             continue;
         }
         // If the GET method is allowed we also need to allow the HEAD method
         // since HEAD is a GET method that doesn't return the body.
         if (in_array('GET', $supported_methods, TRUE)) {
             $supported_methods[] = 'HEAD';
         }
         if (!in_array($method, $supported_methods, TRUE)) {
             $all_supported_methods = array_merge($supported_methods, $all_supported_methods);
             $collection->remove($name);
         }
     }
     if (count($collection)) {
         return $collection;
     }
     throw new MethodNotAllowedException(array_unique($all_supported_methods));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:30,代码来源:MethodFilter.php

示例5: describeRouteCollection

 /**
  * {@inheritdoc}
  */
 protected function describeRouteCollection(RouteCollection $routes, array $options = array())
 {
     $showControllers = isset($options['show_controllers']) && $options['show_controllers'];
     $tableHeaders = array('Name', 'Method', 'Scheme', 'Host', 'Path');
     if ($showControllers) {
         $tableHeaders[] = 'Controller';
     }
     $tableRows = array();
     foreach ($routes->all() as $name => $route) {
         $row = array($name, $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', '' !== $route->getHost() ? $route->getHost() : 'ANY', $route->getPath());
         if ($showControllers) {
             $controller = $route->getDefault('_controller');
             if ($controller instanceof \Closure) {
                 $controller = 'Closure';
             } elseif (is_object($controller)) {
                 $controller = get_class($controller);
             }
             $row[] = $controller;
         }
         $tableRows[] = $row;
     }
     if (isset($options['output'])) {
         $options['output']->table($tableHeaders, $tableRows);
     } else {
         $table = new Table($this->getOutput());
         $table->setHeaders($tableHeaders)->setRows($tableRows);
         $table->render();
     }
 }
开发者ID:robhaverkort,项目名称:belasting,代码行数:32,代码来源:TextDescriptor.php

示例6: describeRouteCollection

    /**
     * {@inheritdoc}
     */
    protected function describeRouteCollection(RouteCollection $routes, array $options = array())
    {
        $showControllers = isset($options['show_controllers']) && $options['show_controllers'];
        $headers = array('Name', 'Method', 'Scheme', 'Host', 'Path');
        $table = new TableHelper();
        $table->setLayout(TableHelper::LAYOUT_COMPACT);
        $table->setHeaders($showControllers ? array_merge($headers, array('Controller')) : $headers);

        foreach ($routes->all() as $name => $route) {
            $row = array(
                $name,
                $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY',
                $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY',
                '' !== $route->getHost() ? $route->getHost() : 'ANY',
                $route->getPath(),
            );

            if ($showControllers) {
                $controller = $route->getDefault('_controller');
                if ($controller instanceof \Closure) {
                    $controller = 'Closure';
                } elseif (is_object($controller)) {
                    $controller = get_class($controller);
                }
                $row[] = $controller;
            }

            $table->addRow($row);
        }

        $this->writeText($this->formatSection('router', 'Current routes')."\n", $options);
        $this->renderTable($table, !(isset($options['raw_output']) && $options['raw_output']));
    }
开发者ID:Gregwar,项目名称:symfony,代码行数:36,代码来源:TextDescriptor.php

示例7: getRouteCollection

 /**
  * {@inheritdoc}
  */
 public function getRouteCollection()
 {
     static $i18nCollection;
     if ($i18nCollection instanceof RouteCollection === false) {
         if (null === $this->collection) {
             $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
         }
         $i18nCollection = new RouteCollection();
         foreach ($this->collection->getResources() as $resource) {
             $i18nCollection->addResource($resource);
         }
         foreach ($this->collection->all() as $name => $route) {
             //do not add i18n routing prefix
             if ($this->shouldExcludeRoute($name, $route)) {
                 $i18nCollection->add($name, $route);
                 continue;
             }
             //add i18n routing prefix
             foreach ($this->generateI18nPatterns($name, $route) as $pattern => $locales) {
                 foreach ($locales as $locale) {
                     $localeRoute = clone $route;
                     $localeRoute->setPath($pattern);
                     $localeRoute->setDefault('_locale', $locale);
                     $i18nCollection->add($locale . self::ROUTING_PREFIX . $name, $localeRoute);
                 }
             }
         }
     }
     return $i18nCollection;
 }
开发者ID:pitpit,项目名称:HipI18nRoutingBundle,代码行数:33,代码来源:I18nRouter.php

示例8: alterRoutes

 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->entityStorage->loadMultiple() as $entity_id => $entity) {
         /** @var $entity \Drupal\page_manager\PageInterface */
         // If the page is disabled skip making a route for it.
         if (!$entity->status() || $entity->isFallbackPage()) {
             continue;
         }
         // Prepare a route name to use if this is a custom page.
         $route_name = "page_manager.page_view_{$entity_id}";
         // Prepare the values that need to be altered for an existing page.
         $path = $entity->getPath();
         $parameters = ['page_manager_page' => ['type' => 'entity:page']];
         // Loop through all existing routes to see if this is overriding a route.
         foreach ($collection->all() as $name => $collection_route) {
             // Find all paths which match the path of the current display.
             $route_path = RouteCompiler::getPathWithoutDefaults($collection_route);
             $route_path = RouteCompiler::getPatternOutline($route_path);
             if ($path == $route_path) {
                 // Adjust the path to translate %placeholders to {slugs}.
                 $path = $collection_route->getPath();
                 // Merge in any route parameter definitions.
                 $parameters += $collection_route->getOption('parameters') ?: [];
                 // Update the route name this will be added to.
                 $route_name = $name;
                 // Remove the existing route.
                 $collection->remove($route_name);
                 break;
             }
         }
         // Construct an add a new route.
         $route = new Route($path, ['_entity_view' => 'page_manager_page', 'page_manager_page' => $entity_id, '_title' => $entity->label()], ['_entity_access' => 'page_manager_page.view'], ['parameters' => $parameters, '_admin_route' => $entity->usesAdminTheme()]);
         $collection->add($route_name, $route);
     }
 }
开发者ID:pulibrary,项目名称:recap,代码行数:38,代码来源:PageManagerRoutes.php

示例9: load

 public function load(RouteCollection $collection)
 {
     $i18nCollection = new RouteCollection();
     foreach ($collection->getResources() as $resource) {
         $i18nCollection->addResource($resource);
     }
     $this->patternGenerationStrategy->addResources($i18nCollection);
     foreach ($collection->all() as $name => $route) {
         if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
             $i18nCollection->add($name, $route);
             continue;
         }
         foreach ($this->patternGenerationStrategy->generateI18nPatterns($name, $route) as $pattern => $locales) {
             // If this pattern is used for more than one locale, we need to keep the original route.
             // We still add individual routes for each locale afterwards for faster generation.
             if (count($locales) > 1) {
                 $catchMultipleRoute = clone $route;
                 $catchMultipleRoute->getPath($pattern);
                 $catchMultipleRoute->setDefault('_locales', $locales);
                 $i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchMultipleRoute);
             }
             foreach ($locales as $locale) {
                 $localeRoute = clone $route;
                 $localeRoute->getPath($pattern);
                 $localeRoute->setDefault('_locale', $locale);
                 $i18nCollection->add($locale . I18nLoader::ROUTING_PREFIX . $name, $localeRoute);
             }
         }
     }
     return $i18nCollection;
 }
开发者ID:AntoineLemaire,项目名称:JMSI18nRoutingBundle,代码行数:31,代码来源:I18nLoader.php

示例10: testCheck

 /**
  * Tests \Drupal\Core\Access\AccessManager::check().
  */
 public function testCheck()
 {
     $route_matches = [];
     // Construct route match objects.
     foreach ($this->routeCollection->all() as $route_name => $route) {
         $route_matches[$route_name] = new RouteMatch($route_name, $route, [], []);
     }
     // Check route access without any access checker defined yet.
     foreach ($route_matches as $route_match) {
         $this->assertEquals(FALSE, $this->accessManager->check($route_match, $this->account));
         $this->assertEquals(AccessResult::neutral(), $this->accessManager->check($route_match, $this->account, NULL, TRUE));
     }
     $this->setupAccessChecker();
     // An access checker got setup, but the routes haven't been setup using
     // setChecks.
     foreach ($route_matches as $route_match) {
         $this->assertEquals(FALSE, $this->accessManager->check($route_match, $this->account));
         $this->assertEquals(AccessResult::neutral(), $this->accessManager->check($route_match, $this->account, NULL, TRUE));
     }
     // Now applicable access checks have been saved on each route object.
     $this->checkProvider->setChecks($this->routeCollection);
     $this->setupAccessArgumentsResolverFactory();
     $this->assertEquals(FALSE, $this->accessManager->check($route_matches['test_route_1'], $this->account));
     $this->assertEquals(TRUE, $this->accessManager->check($route_matches['test_route_2'], $this->account));
     $this->assertEquals(FALSE, $this->accessManager->check($route_matches['test_route_3'], $this->account));
     $this->assertEquals(TRUE, $this->accessManager->check($route_matches['test_route_4'], $this->account));
     $this->assertEquals(AccessResult::neutral(), $this->accessManager->check($route_matches['test_route_1'], $this->account, NULL, TRUE));
     $this->assertEquals(AccessResult::allowed(), $this->accessManager->check($route_matches['test_route_2'], $this->account, NULL, TRUE));
     $this->assertEquals(AccessResult::forbidden(), $this->accessManager->check($route_matches['test_route_3'], $this->account, NULL, TRUE));
     $this->assertEquals(AccessResult::allowed(), $this->accessManager->check($route_matches['test_route_4'], $this->account, NULL, TRUE));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:34,代码来源:AccessManagerTest.php

示例11: describeRouteCollection

 /**
  * {@inheritdoc}
  */
 protected function describeRouteCollection(RouteCollection $routes, array $options = array())
 {
     $data = array();
     foreach ($routes->all() as $name => $route) {
         $data[$name] = $this->getRouteData($route);
     }
     $this->writeData($data, $options);
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:11,代码来源:JsonDescriptor.php

示例12: dump

    function dump()
    {
        $stamp = new \DateTime();
        $time = $stamp->format("r");
        $result = <<<EOF
<?php
/**
 *
 * Route Dump
 * This is a generated file , do not edit 
 * <timestamp>{$time}</timestamp>              
 */
                
 use Symfony\\Component\\Routing\\RouteCollection;
 use Symfony\\Component\\Routing\\Route;
        
 \$routeCollection = new RouteCollection();
                
        
EOF;
        $fields = array("Defaults", "Host", "Methods", "Options", "Path", "Requirements", "Schemes");
        foreach ($this->routeCollection->all() as $name => $route) {
            $result .= <<<EOF


/**
 *                    
 * route named {$name}
 *                    
 */                   
EOF;
            $route_name = "\$route" . preg_replace("/!\\W/im", "_", $name);
            $result .= "\n{$route_name} = new Route(" . var_export($route->getPath(), true) . ");";
            /* @var $route Route */
            foreach ($fields as $field) {
                if ($route->{"get{$field}"}() != null) {
                    $result .= "\n{$route_name}->set{$field}(" . var_export($route->{"get{$field}"}(), true) . ");";
                }
            }
            // echo $name;
            //print_r($route);
            $result .= "\n\$routeCollection->add('{$name}',{$route_name});";
        }
        $result .= "\nreturn \$routeCollection;";
        return $result;
    }
开发者ID:mparaiso,项目名称:routeconfigserviceprovider,代码行数:46,代码来源:PHPDumper.php

示例13: alterRoutes

 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($collection->all() as $route) {
         if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route')) {
             $route->setOption('_admin_route', TRUE);
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:AdminRouteSubscriber.php

示例14: all

 /**
  * Returns all routes in this collection.
  *
  * @return Route[] An array of routes
  */
 public function all()
 {
     $routeCollectionAll = new RouteCollection();
     foreach ($this->routeCollections as $routeCollection) {
         $routeCollectionAll->addCollection($routeCollection);
     }
     return $routeCollectionAll->all();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:ChainRouteCollection.php

示例15: currentRouteName

 /**
  * Get the current route name.
  *
  * @return string|null
  */
 public function currentRouteName()
 {
     foreach ($this->routes->all() as $name => $route) {
         if ($route === $this->currentRoute) {
             return $name;
         }
     }
 }
开发者ID:centaurustech,项目名称:sagip,代码行数:13,代码来源:Router.php


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