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


PHP RouteCollection::addRoute方法代码示例

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


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

示例1: testAddPrefix

 public function testAddPrefix()
 {
     $collection = new RouteCollection();
     $collection->addRoute('foo', $foo = new Route('/foo'));
     $collection->addRoute('bar', $bar = new Route('/bar'));
     $collection->addPrefix('/admin');
     $this->assertEquals('/admin/foo', $collection->getRoute('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
     $this->assertEquals('/admin/bar', $collection->getRoute('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:9,代码来源:RouteCollectionTest.php

示例2: testNormalizeUrl

 public function testNormalizeUrl()
 {
     $collection = new RouteCollection();
     $collection->addRoute('foo', new Route('/:foo'));
     $matcher = new UrlMatcherForTests($collection, array(), array());
     $this->assertEquals('/', $matcher->normalizeUrl(''), '->normalizeUrl() adds a / at the beginning of the URL if needed');
     $this->assertEquals('/foo', $matcher->normalizeUrl('foo'), '->normalizeUrl() adds a / at the beginning of the URL if needed');
     $this->assertEquals('/foo', $matcher->normalizeUrl('/foo?foo=bar'), '->normalizeUrl() removes the query string');
     $this->assertEquals('/foo/bar', $matcher->normalizeUrl('/foo//bar'), '->normalizeUrl() removes duplicated /');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:10,代码来源:UrlMatcherTest.php

示例3: parseRoute

 /**
  * @throws \InvalidArgumentException When config pattern is not defined for the given route
  */
 protected function parseRoute(RouteCollection $collection, $name, $config, $file)
 {
     $defaults = isset($config['defaults']) ? $config['defaults'] : array();
     $requirements = isset($config['requirements']) ? $config['requirements'] : array();
     $options = isset($config['options']) ? $config['options'] : array();
     if (!isset($config['pattern'])) {
         throw new \InvalidArgumentException(sprintf('You must define a "pattern" for the "%s" route.', $name));
     }
     $route = new Route($config['pattern'], $defaults, $requirements, $options);
     $collection->addRoute($name, $route);
 }
开发者ID:rsky,项目名称:symfony,代码行数:14,代码来源:YamlFileLoader.php

示例4: testLoad

 /**
  * @covers Symfony\Component\Routing\Loader\ClosureLoader::load
  */
 public function testLoad()
 {
     $loader = new ClosureLoader();
     $route = new Route('/');
     $routes = $loader->load(function () use($route) {
         $routes = new RouteCollection();
         $routes->addRoute('foo', $route);
         return $routes;
     });
     $this->assertEquals($route, $routes->getRoute('foo'), '->load() loads a \\Closure resource');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:14,代码来源:ClosureLoaderTest.php

示例5: testLoad

 /**
  * @covers Symfony\Component\Routing\Loader\DelegatingLoader::load
  */
 public function testLoad()
 {
     $resolver = new LoaderResolver(array(new ClosureLoader()));
     $loader = new DelegatingLoader($resolver);
     $route = new Route('/');
     $routes = $loader->load(function () use($route) {
         $routes = new RouteCollection();
         $routes->addRoute('foo', $route);
         return $routes;
     });
     $this->assertSame($route, $routes->getRoute('foo'), '->load() loads a resource using the loaders from the resolver');
     try {
         $loader->load('foo.foo');
         $this->fail('->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     }
 }
开发者ID:netixpro,项目名称:symfony,代码行数:21,代码来源:DelegatingLoaderTest.php

示例6: RouteCollection

<?php

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
$collection = new RouteCollection();
$collection->addRoute('homepage', new Route('/', array('_controller' => 'FrameworkBundle:Default:index')));
return $collection;
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:7,代码来源:routing.php

示例7: load

 /**
  * Loads from annotations from a class.
  *
  * @param  string $class A class name
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When route can't be parsed
  */
 public function load($class)
 {
     if (!class_exists($class)) {
         throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
     }
     $class = new \ReflectionClass($class);
     $annotClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
     $globals = array('pattern' => '', 'requirements' => array(), 'options' => array(), 'defaults' => array());
     if ($annot = $this->reader->getClassAnnotation($class, $annotClass)) {
         if (null !== $annot->getPattern()) {
             $globals['pattern'] = $annot->getPattern();
         }
         if (null !== $annot->getRequirements()) {
             $globals['requirements'] = $annot->getRequirements();
         }
         if (null !== $annot->getOptions()) {
             $globals['options'] = $annot->getOptions();
         }
         if (null !== $annot->getDefaults()) {
             $globals['defaults'] = $annot->getDefaults();
         }
     }
     $this->reader->setDefaultAnnotationNamespace('Symfony\\Component\\Routing\\Annotation\\');
     $collection = new RouteCollection();
     foreach ($class->getMethods() as $method) {
         if ($annot = $this->reader->getMethodAnnotation($method, $annotClass)) {
             if (null === $annot->getName()) {
                 $annot->setName($this->getDefaultRouteName($class, $method));
             }
             $defaults = array_merge($globals['defaults'], $annot->getDefaults(), $this->getRouteDefaults($class, $method, $annot));
             $requirements = array_merge($globals['requirements'], $annot->getRequirements());
             $options = array_merge($globals['options'], $annot->getOptions());
             $route = new Route($globals['pattern'] . $annot->getPattern(), $defaults, $requirements, $options);
             $collection->addRoute($annot->getName(), $route);
         }
     }
     return $collection;
 }
开发者ID:rsky,项目名称:symfony,代码行数:47,代码来源:AnnotationClassLoader.php

示例8: parseRoute

 protected function parseRoute(RouteCollection $collection, $definition, $file)
 {
     $defaults = array();
     $requirements = array();
     $options = array();
     foreach ($definition->childNodes as $node) {
         if (!$node instanceof \DOMElement) {
             continue;
         }
         switch ($node->tagName) {
             case 'default':
                 $defaults[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
                 break;
             case 'option':
                 $options[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
                 break;
             case 'requirement':
                 $requirements[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
         }
     }
     $route = new Route((string) $definition->getAttribute('pattern'), $defaults, $requirements, $options);
     $collection->addRoute((string) $definition->getAttribute('id'), $route);
 }
开发者ID:rsky,项目名称:symfony,代码行数:26,代码来源:XmlFileLoader.php


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