diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c14261a6..01d52ed14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/Routing/Annotation/I18nRoute.php b/src/Routing/Annotation/I18nRoute.php index d56fe066e..689d0d17d 100644 --- a/src/Routing/Annotation/I18nRoute.php +++ b/src/Routing/Annotation/I18nRoute.php @@ -1,4 +1,5 @@ $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) + ); } /** diff --git a/tests/Fixtures/Controller/MissingLocalesController.php b/tests/Fixtures/Controller/MissingLocalesController.php new file mode 100644 index 000000000..3ef713cda --- /dev/null +++ b/tests/Fixtures/Controller/MissingLocalesController.php @@ -0,0 +1,15 @@ +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'); + } }