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


PHP RouteCollection::addCollection方法代碼示例

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


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

示例1: load

 /**
  * @param mixed $resource
  * @param null $type
  * @return \Symfony\Component\Routing\RouteCollection
  * @throws \RuntimeException
  */
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     /*
      * For each core bunle then for each module
      */
     // CoreBundle
     $loader = $this->resolver->resolve('@EtuCoreBundle/Api/Resource/', 'annotation');
     if ($loader) {
         $routes->addCollection($loader->load('@EtuCoreBundle/Api/Resource/', 'annotation'));
     }
     // UserBundle
     $loader = $this->resolver->resolve('@EtuUserBundle/Api/Resource/', 'annotation');
     if ($loader) {
         $routes->addCollection($loader->load('@EtuUserBundle/Api/Resource/', 'annotation'));
     }
     /** @var $module Module */
     foreach ($this->kernel->getModulesDefinitions() as $module) {
         $routing = $module->getApiRouting();
         $loader = $this->resolver->resolve($routing['resource'], $routing['type']);
         if ($loader) {
             $routes->addCollection($loader->load($routing['resource'], $routing['type']));
         }
     }
     return $routes;
 }
開發者ID:ChrisdAutume,項目名稱:EtuUTT,代碼行數:32,代碼來源:ApiResourcesRoutingLoader.php

示例2: addRoutes

 /**
  * {@inheritdoc}
  */
 public function addRoutes(RouteCollection $routes)
 {
     if (empty($this->routes)) {
         $this->routes = $routes;
     } else {
         $this->routes->addCollection($routes);
     }
 }
開發者ID:318io,項目名稱:318-io,代碼行數:11,代碼來源:MatcherDumper.php

示例3: find

 /**
  * Find a list of controllers
  *
  * @param string $base_path Base path to prepend to file paths
  * @return provider
  */
 public function find($base_path = '')
 {
     $this->routes = new RouteCollection();
     foreach ($this->routing_files as $file_path) {
         $loader = new YamlFileLoader(new FileLocator(phpbb_realpath($base_path)));
         $this->routes->addCollection($loader->load($file_path));
     }
     return $this;
 }
開發者ID:Tarendai,項目名稱:spring-website,代碼行數:15,代碼來源:provider.php

示例4: testDump

 public function testDump()
 {
     $collection = new RouteCollection();
     // defaults and requirements
     $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'), array('bar' => 'baz|symfony')));
     // method requirement
     $collection->add('bar', new Route('/bar/{foo}', array(), array('_method' => 'GET|head')));
     // GET method requirement automatically adds HEAD as valid
     $collection->add('barhead', new Route('/barhead/{foo}', array(), array('_method' => 'GET')));
     // simple
     $collection->add('baz', new Route('/test/baz'));
     // simple with extension
     $collection->add('baz2', new Route('/test/baz.html'));
     // trailing slash
     $collection->add('baz3', new Route('/test/baz3/'));
     // trailing slash with variable
     $collection->add('baz4', new Route('/test/{foo}/'));
     // trailing slash and method
     $collection->add('baz5', new Route('/test/{foo}/', array(), array('_method' => 'post')));
     // complex name
     $collection->add('baz.baz6', new Route('/test/{foo}/', array(), array('_method' => 'put')));
     // defaults without variable
     $collection->add('foofoo', new Route('/foofoo', array('def' => 'test')));
     // pattern with quotes
     $collection->add('quoter', new Route('/{quoter}', array(), array('quoter' => '[\']+')));
     // prefixes
     $collection1 = new RouteCollection();
     $collection1->add('foo', new Route('/{foo}'));
     $collection1->add('bar', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b\'b');
     $collection1 = new RouteCollection();
     $collection1->add('foo1', new Route('/{foo1}'));
     $collection1->add('bar1', new Route('/{bar1}'));
     $collection2->addCollection($collection1, '/b\'b');
     $collection->addCollection($collection2, '/a');
     // "dynamic" prefix
     $collection1 = new RouteCollection();
     $collection1->add('foo', new Route('/{foo}'));
     $collection1->add('bar', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b');
     $collection->addCollection($collection2, '/{_locale}');
     $collection->add('ababa', new Route('/ababa'));
     // some more prefixes
     $collection1 = new RouteCollection();
     $collection1->add('foo', new Route('/{foo}'));
     $collection->addCollection($collection1, '/aba');
     $dumper = new PhpMatcherDumper($collection, new RequestContext());
     $this->assertStringEqualsFile(__DIR__ . '/../../Fixtures/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
     // force HTTPS redirection
     $collection->add('secure', new Route('/secure', array(), array('_scheme' => 'https')));
     // force HTTP redirection
     $collection->add('nonsecure', new Route('/nonsecure', array(), array('_scheme' => 'http')));
     $this->assertStringEqualsFile(__DIR__ . '/../../Fixtures/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\\Tests\\Component\\Routing\\Fixtures\\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.');
 }
開發者ID:rfc1483,項目名稱:padel,代碼行數:56,代碼來源:PhpMatcherDumperTest.php

示例5: getRouteCollection

 protected function getRouteCollection()
 {
     $collection = new RouteCollection();
     $collection->add('overriden', new Route('/overriden'));
     // defaults and requirements
     $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'), array('bar' => 'baz|symfony')));
     // method requirement
     $collection->add('bar', new Route('/bar/{foo}', array(), array('_method' => 'GET|head')));
     // GET method requirement automatically adds HEAD as valid
     $collection->add('barhead', new Route('/barhead/{foo}', array(), array('_method' => 'GET')));
     // simple
     $collection->add('baz', new Route('/test/baz'));
     // simple with extension
     $collection->add('baz2', new Route('/test/baz.html'));
     // trailing slash
     $collection->add('baz3', new Route('/test/baz3/'));
     // trailing slash with variable
     $collection->add('baz4', new Route('/test/{foo}/'));
     // trailing slash and method
     $collection->add('baz5', new Route('/test/{foo}/', array(), array('_method' => 'post')));
     // complex name
     $collection->add('baz.baz6', new Route('/test/{foo}/', array(), array('_method' => 'put')));
     // defaults without variable
     $collection->add('foofoo', new Route('/foofoo', array('def' => 'test')));
     // pattern with quotes
     $collection->add('quoter', new Route('/{quoter}', array(), array('quoter' => '[\']+')));
     // prefixes
     $collection1 = new RouteCollection();
     $collection1->add('overriden', new Route('/overriden1'));
     $collection1->add('foo1', new Route('/{foo}'));
     $collection1->add('bar1', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b\'b');
     $collection2->add('overriden', new Route('/overriden2'));
     $collection1 = new RouteCollection();
     $collection1->add('foo2', new Route('/{foo1}'));
     $collection1->add('bar2', new Route('/{bar1}'));
     $collection2->addCollection($collection1, '/b\'b');
     $collection->addCollection($collection2, '/a');
     // "dynamic" prefix
     $collection1 = new RouteCollection();
     $collection1->add('foo3', new Route('/{foo}'));
     $collection1->add('bar3', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b');
     $collection->addCollection($collection2, '/{_locale}');
     $collection->add('ababa', new Route('/ababa'));
     // some more prefixes
     $collection1 = new RouteCollection();
     $collection1->add('foo4', new Route('/{foo}'));
     $collection->addCollection($collection1, '/aba');
     return $collection;
 }
開發者ID:robertowest,項目名稱:CuteFlow-V4,代碼行數:53,代碼來源:PhpMatcherDumperTest.php

示例6: load

 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     $collection = new RouteCollection();
     $resource = __DIR__ . '/../Resources/config';
     $locator = new FileLocator($resource);
     $loader = new YamlFileLoader($locator);
     $collection->addCollection($loader->load('routing.yml'));
     $collection->addCollection($loader->load('routing_admin.yml'));
     $this->loaded = true;
     return $collection;
 }
開發者ID:c4d3r,項目名稱:mcsuite-application-eyeofender,代碼行數:14,代碼來源:RouteLoader.php

示例7: load

 /**
  * {@inheritdoc}
  */
 public function load($data, $type = null)
 {
     $routeCollection = new RouteCollection();
     $routeCollection->addCollection($this->fileLoader->load('json_ld.xml'));
     $routeCollection->addCollection($this->fileLoader->load('hydra.xml'));
     foreach ($this->resourceCollection as $resource) {
         foreach ($resource->getCollectionOperations() as $operation) {
             $routeCollection->add($operation->getRouteName(), $operation->getRoute());
         }
         foreach ($resource->getItemOperations() as $operation) {
             $routeCollection->add($operation->getRouteName(), $operation->getRoute());
         }
     }
     return $routeCollection;
 }
開發者ID:reminec,項目名稱:DunglasApiBundle,代碼行數:18,代碼來源:ApiLoader.php

示例8: load

 /**
  * @todo clean this
  */
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     $routes = new RouteCollection();
     $frontPageConfig = $this->container->get('system')->get('system.frontpage', 'blog');
     $frontPageProvider = $this->container->get('drafterbit_system.frontpage_provider');
     $reservedBaseUrl = [$this->container->getParameter('admin')];
     foreach ($frontPageProvider->all() as $prefix => $frontPage) {
         $frontRoutes = $frontPage->getRoutes();
         if ($prefix !== $frontPageConfig) {
             $frontRoutes->addPrefix($frontPage->getRoutePrefix());
             $reservedBaseUrl[] = $prefix;
         }
         $routes->addCollection($frontRoutes);
     }
     $defaults = array('_controller' => 'DrafterbitPageBundle:Frontend:view');
     // check if configured frontpage is not an app
     if (!array_key_exists($frontPageConfig, $frontPageProvider->all())) {
         // its page
         $defaults['slug'] = $frontPageConfig;
         $routes->add('_home', new Route('/', $defaults));
     }
     $reservedBaseUrl = implode('|', $reservedBaseUrl);
     // @link http://stackoverflow.com/questions/25496704/regex-match-slug-except-particular-start-words
     // @prototype  'slug' => "^(?!(?:backend|blog)(?:/|$)).*$"
     $requirements = array('slug' => "^(?!(?:%admin%|" . $reservedBaseUrl . "|)(?:/|\$)).*\$");
     $route2 = new Route('/{slug}', $defaults, $requirements);
     $routes->add('misc', $route2);
     return $routes;
 }
開發者ID:hikmahtiar6,項目名稱:drafterbit,代碼行數:35,代碼來源:FrontendLoader.php

示例9: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     $collection = new RouteCollection();
     foreach ($this->localeResolver->getDomainConfig() as $_domain => $_locale) {
         $_collection = parent::load($resource, $type);
         foreach ($_collection->all() as $_name => $_route) {
             $_route->addDefaults(['_locale' => $_locale]);
             $_route->setHost($_domain);
             $collection->add($_locale . '__' . $this->urlizer->urlize($_domain, '_') . '__' . $_name, $_route);
         }
     }
     /*
      * Add default(fallback) route for default locale/domain
      * needs to be after the loop
      * */
     $defaultCollection = parent::load($resource, $type);
     $defaultCollection->addDefaults(['_locale' => $this->localeResolver->defaultLocale]);
     $collection->addCollection($defaultCollection);
     if ($this->localeResolver->localePattern == LocaleResolver::PATTERN_PARAMETER) {
         $collection = parent::load($resource, $type);
         //Prefix every victoire route with the locale
         $collection->addPrefix('/{_locale}');
         $collection->addCollection($collection);
         //Add a redirection to the default locale homepage when empty url '/'
         $this->addHomepageRedirection($collection);
     }
     return $collection;
 }
開發者ID:victoire,項目名稱:victoire,代碼行數:31,代碼來源:I18nRouteLoader.php

示例10: load

 /**
  * @param string $resource
  * @param null $type
  * @return \Symfony\Component\Routing\RouteCollection
  */
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     $logger = $this->container->get('logger');
     $logger->info('Загрузка рубрик для построения роутинга');
     $a = microtime(true);
     $rubrics = $this->em->getRepository('ApplicationIphpCoreBundle:Rubric')->createQueryBuilder('r')->orderBy('r.level', 'DESC')->getQuery()->getResult();
     foreach ($rubrics as $rubric) {
         $controller = $rubric->getControllerName();
         $rubricRoutes = null;
         //В контроллере можеть быть: Класс модуля
         if ($controller && substr($controller, -6) == 'Module') {
             $module = $this->moduleManager->getModuleFromRubric($rubric);
             if ($module) {
                 $rubricRoutes = $module->getRoutes();
             }
         }
         if ($rubricRoutes) {
             foreach ($rubricRoutes as $route) {
                 $route->setDefault('_rubric', $rubric->getFullPath());
             }
             $routes->addCollection($rubricRoutes, substr($rubric->getFullPath(), 0, -1));
         }
     }
     $b = microtime(true) - $a;
     $logger->info('Загрузили роуты за' . $b . ' с');
     return $routes;
 }
開發者ID:khasinski,項目名稱:Iphp,代碼行數:33,代碼來源:RubricRouteLoader.php

示例11: load

 /**
  * Loads a Yaml file.
  *
  * @param string $file A Yaml file path
  * @param string $type The resource type
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When route can't be parsed
  */
 public function load($file, $type = null)
 {
     $path = $this->findFile($file);
     $config = $this->loadFile($path);
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($path));
     // empty file
     if (null === $config) {
         $config = array();
     }
     // not an array
     if (!is_array($config)) {
         throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file));
     }
     foreach ($config as $name => $config) {
         if (isset($config['resource'])) {
             $type = isset($config['type']) ? $config['type'] : null;
             $prefix = isset($config['prefix']) ? $config['prefix'] : null;
             $this->currentDir = dirname($path);
             $collection->addCollection($this->import($config['resource'], $type), $prefix);
         } elseif (isset($config['pattern'])) {
             $this->parseRoute($collection, $name, $config, $path);
         } else {
             throw new \InvalidArgumentException(sprintf('Unable to parse the "%s" route.', $name));
         }
     }
     return $collection;
 }
開發者ID:notbrain,項目名稱:symfony,代碼行數:38,代碼來源:YamlFileLoader.php

示例12: addGroup

 public function addGroup($config, $callback)
 {
     $router = $this->getSubRouter();
     if (is_callable($callback)) {
         $callback($router);
     } else {
         $e = new Error();
         $e->log(new \Exception('Segundo parâmetro não é uma função do tipo callable'));
     }
     $sub_collection = $router->getCollection();
     if (isset($config['defaults'])) {
         $sub_collection->addDefaults($config['defaults']);
     }
     if (isset($config['mask'])) {
         $sub_collection->addRequirements($config['mask']);
     }
     if (isset($config['options'])) {
         $sub_collection->addOptions($config['options']);
     }
     if (isset($config['host'])) {
         $sub_collection->setHost($config['host']);
     }
     if (isset($config['schemes'])) {
         $sub_collection->setSchemes($config['schemes']);
     }
     if (isset($config['methods'])) {
         $sub_collection->setMethods($config['methods']);
     }
     $this->collection->addCollection($sub_collection);
 }
開發者ID:anna-framework,項目名稱:anna,代碼行數:30,代碼來源:RouterTrait.php

示例13: load

 /**
  * Loads a Yaml file.
  *
  * @param string $file A Yaml file path
  * @param string $type The resource type
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When route can't be parsed
  *
  * @api
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     $config = Yaml::parse($path);
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($path));
     // empty file
     if (null === $config) {
         $config = array();
     }
     // not an array
     if (!is_array($config)) {
         throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file));
     }
     foreach ($config as $name => $config) {
         $config = $this->normalizeRouteConfig($config);
         if (isset($config['resource'])) {
             $type = isset($config['type']) ? $config['type'] : null;
             $prefix = isset($config['prefix']) ? $config['prefix'] : null;
             $defaults = isset($config['defaults']) ? $config['defaults'] : array();
             $requirements = isset($config['requirements']) ? $config['requirements'] : array();
             $options = isset($config['options']) ? $config['options'] : array();
             $this->setCurrentDir(dirname($path));
             $collection->addCollection($this->import($config['resource'], $type, false, $file), $prefix, $defaults, $requirements, $options);
         } else {
             $this->parseRoute($collection, $name, $config, $path);
         }
     }
     return $collection;
 }
開發者ID:laubosslink,項目名稱:lab,代碼行數:42,代碼來源:YamlFileLoader.php

示例14: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     if (true === $this->isLoaded) {
         throw new \RuntimeException('Do not add the "modera_routing" loader twice');
     }
     $resources = array();
     $items = $this->resourcesProvider->getItems();
     foreach ($items as $index => $resource) {
         if (!is_array($resource)) {
             $resource = array('resource' => $resource);
         }
         $resource = array_merge(array('order' => 0, 'type' => null), $resource);
         $resource['index'] = $index;
         $resources[] = $resource;
     }
     usort($resources, function ($a, $b) {
         if ($a['order'] == $b['order']) {
             return $a['index'] < $b['index'] ? -1 : 1;
         }
         return $a['order'] < $b['order'] ? -1 : 1;
     });
     $collection = new RouteCollection();
     foreach ($resources as $item) {
         $collection->addCollection($this->rootLoader->load($item['resource'], $item['type']));
     }
     $this->isLoaded = true;
     return $collection;
 }
開發者ID:modera,項目名稱:foundation,代碼行數:31,代碼來源:Loader.php

示例15: loadRouteCollectionFromFiles

 /**
  * @param string[] $paths
  */
 protected function loadRouteCollectionFromFiles(array $paths) : RouteCollection
 {
     $routeCollection = new RouteCollection();
     foreach ($paths as $path) {
         $routeCollection->addCollection($this->loadRouteCollectionFromFile($path));
     }
     return $routeCollection;
 }
開發者ID:Symplify,項目名稱:ModularRouting,代碼行數:11,代碼來源:AbstractRouteCollectionProvider.php


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