Description
Symfony version(s) affected
6.2-beta
Description
The new Psr4DirectoryLoader
only supports attribute
or annotation
type so it will use the AnnotationClassLoader
which don’t want to deal with abstract classes:
symfony/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
Lines 114 to 116 in b02a689
(See 946ccb6 for rationale.)
If AnnotationDirectoryLoader
skips them, Psr4DirectoryLoader
does not meaning it will crash on abstract classes.
How to reproduce
Configure your routes to use the PSR-4 route loader, eg.
<?php
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return static function (RoutingConfigurator $routes)
{
$routes->import(['path' => '../src/Controller', 'namespace' => 'App\Controller'], 'annotation');
};
and make one of your controllers extends an abstract one (it does not need to define any method).
Refresh the cache to see the error.
Possible Solution
Psr4DirectoryLoader
should skip abstract classes. As it means it will need to create an instance of ReflectionClass
it could be useful to make AnnotationClassLoader::load
accept these.
Additional Context
Spotted from #48161