diff --git a/src/Routing/Annotation/I18nRoute.php b/src/Routing/Annotation/I18nRoute.php index 689d0d17d..730a18458 100644 --- a/src/Routing/Annotation/I18nRoute.php +++ b/src/Routing/Annotation/I18nRoute.php @@ -2,23 +2,20 @@ namespace BeSimple\I18nRoutingBundle\Routing\Annotation; +use Symfony\Component\Routing\Annotation\Route as BaseRoute; + /** * Annotation class for @I18nRoute(). * * @Annotation * @Target({"CLASS", "METHOD"}) */ -class I18nRoute +class I18nRoute extends BaseRoute { - private $locales; - private $name; - private $requirements = array(); - private $options = array(); - private $defaults = array(); - private $host; - private $methods = array(); - private $schemes = array(); - private $condition; + protected $locales; + protected $requirements = array(); + protected $methods = array(); + protected $schemes = array(); /** * Constructor. @@ -34,13 +31,7 @@ public function __construct(array $data) unset($data['value']); } - foreach ($data as $key => $value) { - $method = 'set'.str_replace('_', '', $key); - if (!method_exists($this, $method)) { - throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, get_class($this))); - } - $this->$method($value); - } + parent::__construct($data); } public function setLocales($locales) @@ -53,26 +44,6 @@ public function getLocales() return $this->locales; } - public function setHost($pattern) - { - $this->host = $pattern; - } - - public function getHost() - { - return $this->host; - } - - public function setName($name) - { - $this->name = $name; - } - - public function getName() - { - return $this->name; - } - public function setRequirements($requirements) { if (isset($requirements['_method'])) { @@ -95,26 +66,6 @@ public function getRequirements() return $this->requirements; } - public function setOptions($options) - { - $this->options = $options; - } - - public function getOptions() - { - return $this->options; - } - - public function setDefaults($defaults) - { - $this->defaults = $defaults; - } - - public function getDefaults() - { - return $this->defaults; - } - public function setSchemes($schemes) { $this->schemes = is_array($schemes) ? $schemes : array($schemes); @@ -134,14 +85,4 @@ public function getMethods() { return $this->methods; } - - public function setCondition($condition) - { - $this->condition = $condition; - } - - public function getCondition() - { - return $this->condition; - } } diff --git a/src/Routing/Loader/AnnotatedRouteControllerLoader.php b/src/Routing/Loader/AnnotatedRouteControllerLoader.php index 8aa940b3a..80a7fc1ce 100644 --- a/src/Routing/Loader/AnnotatedRouteControllerLoader.php +++ b/src/Routing/Loader/AnnotatedRouteControllerLoader.php @@ -2,6 +2,7 @@ namespace BeSimple\I18nRoutingBundle\Routing\Loader; +use BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute; use BeSimple\I18nRoutingBundle\Routing\Exception\MissingLocaleException; use BeSimple\I18nRoutingBundle\Routing\Exception\MissingRouteLocaleException; use BeSimple\I18nRoutingBundle\Routing\RouteGenerator\I18nRouteGenerator; @@ -26,12 +27,17 @@ public function __construct(Reader $reader, RouteGeneratorInterface $routeGenera parent::__construct($reader); $this->routeGenerator = $routeGenerator ?: new I18nRouteGenerator(); - $this->setRouteAnnotationClass('BeSimple\\I18nRoutingBundle\\Routing\\Annotation\\I18nRoute'); + $this->setRouteAnnotationClass('Symfony\\Component\\Routing\\Annotation\\Route'); } protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method) { - /** @var \BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute $annot */ + if (!$annot instanceof I18nRoute) { + parent::addRoute($collection, $annot, $globals, $class, $method); + + return; + } + $name = $annot->getName(); if (null === $name) { $name = $this->getDefaultRouteName($class, $method); @@ -115,51 +121,15 @@ protected function getGlobals(\ReflectionClass $class) { $globals = array( 'locales' => '', - 'requirements' => array(), - 'options' => array(), - 'defaults' => array(), - 'schemes' => array(), - 'methods' => array(), - 'host' => '', - 'condition' => '', ); - /** @var \BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute $annot */ if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) { - if (null !== $annot->getLocales()) { + if ($annot instanceof I18nRoute && null !== $annot->getLocales()) { $globals['locales'] = $annot->getLocales(); } - - if (null !== $annot->getRequirements()) { - $globals['requirements'] = $annot->getRequirements(); - } - - if (null !== $annot->getOptions()) { - $globals['options'] = $annot->getOptions(); - } - - if (null !== $annot->getDefaults()) { - $globals['defaults'] = $annot->getDefaults(); - } - - if (null !== $annot->getSchemes()) { - $globals['schemes'] = $annot->getSchemes(); - } - - if (null !== $annot->getMethods()) { - $globals['methods'] = $annot->getMethods(); - } - - if (null !== $annot->getHost()) { - $globals['host'] = $annot->getHost(); - } - - if (null !== $annot->getCondition()) { - $globals['condition'] = $annot->getCondition(); - } } - return $globals; + return array_merge(parent::getGlobals($class), $globals); } /**