Skip to content

Commit dbca4a9

Browse files
authored
Merge pull request #87 from HeahDude/fix
Minor fixes after #81
2 parents 66665e8 + ad6b219 commit dbca4a9

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To get the diff between two versions, go to https://github.com/BeSimple/BeSimple
1010
* bugs #80 Set be_simple_i18n_routing.doctrine_dbal.connection_name parameter (boekkooi)
1111
* bugs #74 Exclude languaged (boekkooi)
1212
* bugs #77, #66 Added Symfony 3 support (boekkooi)
13-
* feature #43 Added annotation loader support for Symfony 3.5 and greater (boekkooi)
13+
* feature #43 Added annotation loader support for Symfony 2.5 and greater (boekkooi)
1414
* feature #80 Introduced RouteNameInflector & RouteGenerator (boekkooi)
1515
* feature #80 Added strict route support (boekkooi)
1616
* feature #80 Implemented DI tests (boekkooi)

src/Routing/Annotation/I18nRoute.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BeSimple\I18nRoutingBundle\Routing\Annotation;
34

45
/**

src/Routing/Loader/AnnotatedRouteControllerLoader.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BeSimple\I18nRoutingBundle\Routing\Loader;
34

45
use BeSimple\I18nRoutingBundle\Routing\Exception\MissingLocaleException;
@@ -82,40 +83,29 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
8283
} else {
8384
foreach ($localesWithPaths as $locale => $localePath) {
8485
if (!isset($globals['locales'][$locale])) {
85-
throw new MissingLocaleException(sprintf(
86-
'Expected global configuration to contain %s for %s::%s',
87-
$locale,
88-
$class->getName(),
89-
$method->getName()
90-
));
86+
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()));
9187
}
92-
9388
$localesWithPaths[$locale] = $globals['locales'][$locale].$localePath;
9489
}
9590
}
9691
} elseif (!is_array($localesWithPaths)) {
97-
throw new MissingRouteLocaleException(sprintf(
98-
'Unsupported locales found for %s::%s',
99-
$class->getName(),
100-
$method->getName()
101-
));
92+
throw new MissingRouteLocaleException(sprintf('Missing locales for controller %s::%s', $class->getName(), $method->getName()));
10293
}
10394

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

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

108-
if ($localesWithPaths !== null) {
109-
$collection->addCollection(
110-
$this->routeGenerator->generateRoutes(
111-
$name,
112-
$localesWithPaths,
113-
$route
114-
)
115-
);
116-
} else {
99+
if (null === $localesWithPaths) {
100+
// Standard route
117101
$collection->add($name, $route);
102+
103+
return;
118104
}
105+
106+
$collection->addCollection(
107+
$this->routeGenerator->generateRoutes($name, $localesWithPaths, $route)
108+
);
119109
}
120110

121111
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller;
4+
5+
use BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute;
6+
7+
class MissingLocalesController
8+
{
9+
/**
10+
* @I18nRoute(name="foo")
11+
*/
12+
public function fooAction()
13+
{
14+
}
15+
}

tests/Routing/Loader/AnnotatedRouteControllerLoaderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BeSimple\I18nRoutingBundle\Tests\Routing\Loader;
34

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

9798
$loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\MissingPrefixedLocalesController');
9899
}
100+
101+
/**
102+
* @expectedException \BeSimple\I18nRoutingBundle\Routing\Exception\MissingRouteLocaleException
103+
*/
104+
public function testRoutesMissingLocales()
105+
{
106+
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
107+
AnnotationRegistry::registerLoader('class_exists');
108+
109+
$loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\MissingLocalesController');
110+
}
99111
}

0 commit comments

Comments
 (0)