Example #1
0
 public function testSettersViaConstruct()
 {
     $route = new Route(array('service' => 'app.test'));
     $this->assertSame('', $route->getPath());
     $this->assertSame('app.test', $route->getService());
     $route = new Route(array('service' => 'app.test', 'path' => '/test/'));
     $this->assertSame('/test/', $route->getPath());
     $this->assertSame('app.test', $route->getService());
 }
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage The service option can only be specified at class level.
  */
 public function testServiceOptionIsNotAllowedOnMethod()
 {
     $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock();
     $reader = $this->getMockBuilder('Doctrine\\Common\\Annotations\\Reader')->setMethods(array('getClassAnnotation', 'getMethodAnnotations'))->disableOriginalConstructor()->getMockForAbstractClass();
     $annotation = new Route(array());
     $annotation->setService('service');
     $reader->expects($this->once())->method('getClassAnnotation')->will($this->returnValue(null));
     $reader->expects($this->once())->method('getMethodAnnotations')->will($this->returnValue(array($annotation)));
     $loader = $this->getMockBuilder('Sensio\\Bundle\\FrameworkExtraBundle\\Routing\\AnnotatedRouteControllerLoader')->setConstructorArgs(array($reader))->getMock();
     $r = new \ReflectionMethod($loader, 'configureRoute');
     $r->setAccessible(true);
     $r->invoke($loader, $route, new \ReflectionClass($this), new \ReflectionMethod($this, 'testServiceOptionIsNotAllowedOnMethod'), null);
 }
Example #3
0
 public function __construct(array $data)
 {
     parent::__construct($data);
     $requirements = $this->getRequirements();
     $requirements['_method'] = $this->getMethod();
     $this->setRequirements($requirements);
 }
Example #4
0
 public function __construct(array $data)
 {
     parent::__construct($data);
     if (!$this->getMethods()) {
         $this->setMethods((array) $this->getMethod());
     }
 }
 /**
  * @param RouteCollection $collection
  * @param $annot
  * @param $globals
  * @param \ReflectionClass $class
  * @param \ReflectionMethod $method
  */
 protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
 {
     $i18n = isset($annot->data['i18n']) ? $annot->data['i18n'] : true;
     unset($annot->data['i18n']);
     foreach ($this->registry->getRegisteredLocales() as $locale) {
         $i18nAnnot = new Route($annot->data);
         $i18nGlobals = $globals;
         if ($i18n) {
             $i18nAnnot->setName($this->helper->alterName($i18nAnnot->getName(), $locale));
             $i18nAnnot->setPath($this->helper->alterPath($i18nAnnot->getPath(), $locale));
             $i18nAnnot->setDefaults($this->helper->alterDefaults($i18nAnnot->getDefaults(), $locale));
             if (isset($i18nGlobals['path']) && !empty($i18nGlobals['path'])) {
                 $i18nGlobals['path'] = '/' . $locale . '/' . ltrim($this->helper->alterPath($i18nGlobals['path'], $locale), '/');
             } else {
                 $i18nGlobals['path'] = '/' . $locale;
             }
         }
         parent::addRoute($collection, $i18nAnnot, $i18nGlobals, $class, $method);
     }
 }