-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRouteChoiceType.php
More file actions
54 lines (45 loc) · 1.45 KB
/
RouteChoiceType.php
File metadata and controls
54 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Opera\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RouteChoiceType extends AbstractType
{
private $routes;
public function __construct(RouterInterface $router)
{
foreach ($router->getRouteCollection()->all() as $routeName => $route) {
if ($route->getDefault("_controller")) {
$controllerName = $this->getControllerName($route->getDefault("_controller"));
if ($controllerName) {
$this->routes[$controllerName][$routeName] = $routeName;
} else {
$this->routes["Other"][$routeName] = $routeName;
}
}
}
}
/**
* ex:
* input -> "Opera\AdminBundle\Controller\AdminPagesController::layout"
* output -> "AdminPagesController"
*/
private function getControllerName(string $controllerRoutePath)
{
preg_match('/.*\\\\(.*)::.*/', $controllerRoutePath, $matches);
if (!isset($matches[1])) {
return null;
}
return $matches[1];
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'choices' => $this->routes,
]);
}
public function getParent()
{
return \Symfony\Component\Form\Extension\Core\Type\ChoiceType::class;
}
}