Skip to content

Commit

Permalink
Merge pull request #87 from HeahDude/fix
Browse files Browse the repository at this point in the history
Minor fixes after #81
  • Loading branch information
boekkooi authored Jul 12, 2016
2 parents 66665e8 + ad6b219 commit dbca4a9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To get the diff between two versions, go to https://github.com/BeSimple/BeSimple
* bugs #80 Set be_simple_i18n_routing.doctrine_dbal.connection_name parameter (boekkooi)
* bugs #74 Exclude languaged (boekkooi)
* bugs #77, #66 Added Symfony 3 support (boekkooi)
* feature #43 Added annotation loader support for Symfony 3.5 and greater (boekkooi)
* feature #43 Added annotation loader support for Symfony 2.5 and greater (boekkooi)
* feature #80 Introduced RouteNameInflector & RouteGenerator (boekkooi)
* feature #80 Added strict route support (boekkooi)
* feature #80 Implemented DI tests (boekkooi)
Expand Down
1 change: 1 addition & 0 deletions src/Routing/Annotation/I18nRoute.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace BeSimple\I18nRoutingBundle\Routing\Annotation;

/**
Expand Down
32 changes: 11 additions & 21 deletions src/Routing/Loader/AnnotatedRouteControllerLoader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace BeSimple\I18nRoutingBundle\Routing\Loader;

use BeSimple\I18nRoutingBundle\Routing\Exception\MissingLocaleException;
Expand Down Expand Up @@ -82,40 +83,29 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
} else {
foreach ($localesWithPaths as $locale => $localePath) {
if (!isset($globals['locales'][$locale])) {
throw new MissingLocaleException(sprintf(
'Expected global configuration to contain %s for %s::%s',
$locale,
$class->getName(),
$method->getName()
));
throw new MissingLocaleException(sprintf('Locale "%s" for controller %s::%s is expected to be part of the global configuration at class level.', $locale, $class->getName(), $method->getName()));
}

$localesWithPaths[$locale] = $globals['locales'][$locale].$localePath;
}
}
} elseif (!is_array($localesWithPaths)) {
throw new MissingRouteLocaleException(sprintf(
'Unsupported locales found for %s::%s',
$class->getName(),
$method->getName()
));
throw new MissingRouteLocaleException(sprintf('Missing locales for controller %s::%s', $class->getName(), $method->getName()));
}

$route = $this->createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);

$this->configureRoute($route, $class, $method, $annot);

if ($localesWithPaths !== null) {
$collection->addCollection(
$this->routeGenerator->generateRoutes(
$name,
$localesWithPaths,
$route
)
);
} else {
if (null === $localesWithPaths) {
// Standard route
$collection->add($name, $route);

return;
}

$collection->addCollection(
$this->routeGenerator->generateRoutes($name, $localesWithPaths, $route)
);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Fixtures/Controller/MissingLocalesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller;

use BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute;

class MissingLocalesController
{
/**
* @I18nRoute(name="foo")
*/
public function fooAction()
{
}
}
12 changes: 12 additions & 0 deletions tests/Routing/Loader/AnnotatedRouteControllerLoaderTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace BeSimple\I18nRoutingBundle\Tests\Routing\Loader;

use BeSimple\I18nRoutingBundle\Routing\Loader\AnnotatedRouteControllerLoader;
Expand Down Expand Up @@ -96,4 +97,15 @@ public function testRoutesMissingPrefixLocale()

$loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\MissingPrefixedLocalesController');
}

/**
* @expectedException \BeSimple\I18nRoutingBundle\Routing\Exception\MissingRouteLocaleException
*/
public function testRoutesMissingLocales()
{
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
AnnotationRegistry::registerLoader('class_exists');

$loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\MissingLocalesController');
}
}

0 comments on commit dbca4a9

Please sign in to comment.