Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 8 additions & 67 deletions src/Routing/Annotation/I18nRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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'])) {
Expand All @@ -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);
Expand All @@ -134,14 +85,4 @@ public function getMethods()
{
return $this->methods;
}

public function setCondition($condition)
{
$this->condition = $condition;
}

public function getCondition()
{
return $this->condition;
}
}
50 changes: 10 additions & 40 deletions src/Routing/Loader/AnnotatedRouteControllerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down