|
1 | 1 | <?php |
| 2 | + |
2 | 3 | namespace BeSimple\I18nRoutingBundle\Routing\Loader; |
3 | 4 |
|
4 | 5 | use BeSimple\I18nRoutingBundle\Routing\Exception\MissingLocaleException; |
@@ -82,40 +83,29 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl |
82 | 83 | } else { |
83 | 84 | foreach ($localesWithPaths as $locale => $localePath) { |
84 | 85 | 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())); |
91 | 87 | } |
92 | | - |
93 | 88 | $localesWithPaths[$locale] = $globals['locales'][$locale].$localePath; |
94 | 89 | } |
95 | 90 | } |
96 | 91 | } 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())); |
102 | 93 | } |
103 | 94 |
|
104 | 95 | $route = $this->createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition); |
105 | 96 |
|
106 | 97 | $this->configureRoute($route, $class, $method, $annot); |
107 | 98 |
|
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 |
117 | 101 | $collection->add($name, $route); |
| 102 | + |
| 103 | + return; |
118 | 104 | } |
| 105 | + |
| 106 | + $collection->addCollection( |
| 107 | + $this->routeGenerator->generateRoutes($name, $localesWithPaths, $route) |
| 108 | + ); |
119 | 109 | } |
120 | 110 |
|
121 | 111 | /** |
|
0 commit comments