diff --git a/Changelog.md b/Changelog.md index ba65045..30ea150 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 1.8.1 + +### Fixed + +- Symfony 6 compatibility issues + ## 1.8.0 ### Added diff --git a/psalm.baseline.xml b/psalm.baseline.xml index eaaae28..260b1e0 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -1,5 +1,19 @@ + + + $bundles + + + iterable + + + $loader->getResolver()->resolve($file, 'php') + + + RouteCollectionBuilder + + ResettableContainerInterface diff --git a/src/AppKernel.php b/src/AppKernel.php index 71aa4d1..2a0817d 100644 --- a/src/AppKernel.php +++ b/src/AppKernel.php @@ -8,6 +8,9 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +use Symfony\Component\Routing\Loader\PhpFileLoader as RoutingPhpFileLoader; +use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouteCollectionBuilder; /** @@ -79,17 +82,17 @@ public function addConfigFile($configFile) $this->configFiles[] = $configFile; } - public function getCacheDir() + public function getCacheDir(): string { return sys_get_temp_dir().'/NyholmBundleTest/'.$this->cachePrefix; } - public function getLogDir() + public function getLogDir(): string { return sys_get_temp_dir().'/NyholmBundleTest/log'; } - public function getProjectDir() + public function getProjectDir(): string { if (null === $this->fakedProjectDir) { return realpath(__DIR__.'/../../../../'); @@ -114,7 +117,7 @@ public function setProjectDir($projectDir) $this->fakedProjectDir = $projectDir; } - public function registerBundles() + public function registerBundles(): iterable { $this->bundlesToRegister = array_unique($this->bundlesToRegister); $bundles = []; @@ -169,21 +172,40 @@ public function registerContainerConfiguration(LoaderInterface $loader) */ public function loadRoutes(LoaderInterface $loader) { - $routes = new RouteCollectionBuilder($loader); + if (class_exists(RoutingConfigurator::class)) { + $file = (new \ReflectionObject($this))->getFileName(); + /** @var RoutingPhpFileLoader $kernelLoader */ + $kernelLoader = $loader->getResolver()->resolve($file, 'php'); + $kernelLoader->setCurrentDir(\dirname($file)); + + $collection = new RouteCollection(); + $configurator = new RoutingConfigurator($collection, $kernelLoader, $file, $file, $this->getEnvironment()); + + if ($this->routingFile) { + $configurator->import($this->routingFile); + } else { + $configurator->import(__DIR__.'/config/routing.yml'); + } - if ($this->routingFile) { - $routes->import($this->routingFile); + return $collection; } else { - $routes->import(__DIR__.'/config/routing.yml'); - } + // Legacy + $routes = new RouteCollectionBuilder($loader); - return $routes->build(); + if ($this->routingFile) { + $routes->import($this->routingFile); + } else { + $routes->import(__DIR__.'/config/routing.yml'); + } + + return $routes->build(); + } } /** * {@inheritdoc} */ - protected function buildContainer() + protected function buildContainer(): ContainerBuilder { $container = parent::buildContainer();