Is there a way to get all controllers (and the class) of a bundle ? Including all parent contollers ?
Thank\'s
Altough there is no offical way to get the controllers, you can use the following code to get all controllers:
$bundles = $this->container->getParameter('kernel.bundles');
$controllers = [];
foreach ($bundles as $bundle) {
$reflection = new \ReflectionClass($bundle);
$controllerDirectory = dirname($reflection->getFileName()) . '/Controller';
if (file_exists($controllerDirectory)) {
$d = dir($controllerDirectory);
while (false !== ($entry = $d->read())) {
if (preg_match("/^([A-Z0-9-_]+Controller).php/i", $entry, $matches)) {
$controllers[] = ['fileName' => $controllerDirectory. '/'. $entry, 'class' => $reflection->getNamespaceName() . '\Controller\\' . $matches[1]];
}
}
$d->close();
}
}
print_r($controllers);