|
8 | 8 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
9 | 9 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
10 | 10 | use Symfony\Component\HttpKernel\Kernel;
|
| 11 | +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; |
| 12 | +use Symfony\Component\Routing\Loader\PhpFileLoader as RoutingPhpFileLoader; |
| 13 | +use Symfony\Component\Routing\RouteCollection; |
11 | 14 | use Symfony\Component\Routing\RouteCollectionBuilder;
|
12 | 15 |
|
13 | 16 | /**
|
@@ -168,15 +171,34 @@ public function registerContainerConfiguration(LoaderInterface $loader)
|
168 | 171 | */
|
169 | 172 | public function loadRoutes(LoaderInterface $loader)
|
170 | 173 | {
|
171 |
| - $routes = new RouteCollectionBuilder($loader); |
| 174 | + if (class_exists(RoutingConfigurator::class)) { |
| 175 | + $file = (new \ReflectionObject($this))->getFileName(); |
| 176 | + /** @var RoutingPhpFileLoader $kernelLoader */ |
| 177 | + $kernelLoader = $loader->getResolver()->resolve($file, 'php'); |
| 178 | + $kernelLoader->setCurrentDir(\dirname($file)); |
| 179 | + |
| 180 | + $collection = new RouteCollection(); |
| 181 | + $configurator = new RoutingConfigurator($collection, $kernelLoader, $file, $file, $this->getEnvironment()); |
| 182 | + |
| 183 | + if ($this->routingFile) { |
| 184 | + $configurator->import($this->routingFile); |
| 185 | + } else { |
| 186 | + $configurator->import(__DIR__.'/config/routing.yml'); |
| 187 | + } |
172 | 188 |
|
173 |
| - if ($this->routingFile) { |
174 |
| - $routes->import($this->routingFile); |
| 189 | + return $collection; |
175 | 190 | } else {
|
176 |
| - $routes->import(__DIR__.'/config/routing.yml'); |
177 |
| - } |
| 191 | + // Legacy |
| 192 | + $routes = new RouteCollectionBuilder($loader); |
178 | 193 |
|
179 |
| - return $routes->build(); |
| 194 | + if ($this->routingFile) { |
| 195 | + $routes->import($this->routingFile); |
| 196 | + } else { |
| 197 | + $routes->import(__DIR__.'/config/routing.yml'); |
| 198 | + } |
| 199 | + |
| 200 | + return $routes->build(); |
| 201 | + } |
180 | 202 | }
|
181 | 203 |
|
182 | 204 | /**
|
|
0 commit comments