@@ -30,47 +30,51 @@ public function isOptional(): bool
30
30
31
31
public function warmUp (string $ cacheDir , ?string $ buildDir = null ): array
32
32
{
33
- $ allRoutes = $ this ->router ->getRouteCollection ();
34
- $ dashboardRoutes = [];
35
-
36
- /** @var Route $route */
37
- foreach ($ allRoutes as $ routeName => $ route ) {
38
- $ controller = $ route ->getDefault ('_controller ' ) ?? '' ;
39
- // controller is defined as $router->add('admin', '/')->controller(DashboardController::class)
40
- if (\is_string ($ controller ) && '' !== $ controller && class_exists ($ controller )) {
41
- $ controller .= '::__invoke ' ;
42
- }
33
+ $ cacheFilename = ($ buildDir ?? $ cacheDir ).'/ ' .self ::DASHBOARD_ROUTES_CACHE ;
43
34
44
- // controller is defined as $router->add('admin', '/')->controller([DashboardController::class, 'index'])
45
- if (\is_array ($ controller )) {
46
- $ controller = $ controller [0 ].':: ' .($ controller [1 ] ?? '__invoke ' );
47
- }
35
+ if (false === file_exists ($ cacheFilename )) {
36
+ $ allRoutes = $ this ->router ->getRouteCollection ();
37
+ $ dashboardRoutes = [];
48
38
49
- $ controller = u ($ controller );
50
- if ($ controller ->isEmpty ()) {
51
- // this happens e.g. when using 'lexik/jwt-authentication-bundle', which defines an empty controller
52
- continue ;
53
- }
39
+ /** @var Route $route */
40
+ foreach ($ allRoutes as $ routeName => $ route ) {
41
+ $ controller = $ route ->getDefault ('_controller ' ) ?? '' ;
42
+ // controller is defined as $router->add('admin', '/')->controller(DashboardController::class)
43
+ if (\is_string ($ controller ) && '' !== $ controller && class_exists ($ controller )) {
44
+ $ controller .= '::__invoke ' ;
45
+ }
54
46
55
- if (!$ controller ->endsWith ('::index ' ) && !$ controller ->endsWith ('::__invoke ' )) {
56
- continue ;
57
- }
47
+ // controller is defined as $router->add('admin', '/')->controller([DashboardController::class, 'index'])
48
+ if (\is_array ($ controller )) {
49
+ $ controller = $ controller [0 ].':: ' .($ controller [1 ] ?? '__invoke ' );
50
+ }
58
51
59
- $ controllerFqcn = $ controller ->beforeLast (':: ' )->toString ();
60
- if (!is_subclass_of ($ controllerFqcn , DashboardControllerInterface::class)) {
61
- continue ;
52
+ $ controller = u ($ controller );
53
+ if ($ controller ->isEmpty ()) {
54
+ // this happens e.g. when using 'lexik/jwt-authentication-bundle', which defines an empty controller
55
+ continue ;
56
+ }
57
+
58
+ if (!$ controller ->endsWith ('::index ' ) && !$ controller ->endsWith ('::__invoke ' )) {
59
+ continue ;
60
+ }
61
+
62
+ $ controllerFqcn = $ controller ->beforeLast (':: ' )->toString ();
63
+ if (!is_subclass_of ($ controllerFqcn , DashboardControllerInterface::class)) {
64
+ continue ;
65
+ }
66
+
67
+ // when using i18n routes, the same controller can be associated to
68
+ // multiple routes (e.g. 'admin.en', 'admin.es', 'admin.fr', etc.)
69
+ $ dashboardRoutes [$ routeName ] = $ controller ->toString ();
62
70
}
63
71
64
- // when using i18n routes, the same controller can be associated to
65
- // multiple routes (e.g. 'admin.en', 'admin.es', 'admin.fr', etc.)
66
- $ dashboardRoutes [$ routeName ] = $ controller ->toString ();
72
+ (new Filesystem ())->dumpFile (
73
+ $ cacheFilename ,
74
+ '<?php return ' .var_export ($ dashboardRoutes , true ).'; '
75
+ );
67
76
}
68
77
69
- (new Filesystem ())->dumpFile (
70
- $ cacheDir .'/ ' .self ::DASHBOARD_ROUTES_CACHE ,
71
- '<?php return ' .var_export ($ dashboardRoutes , true ).'; '
72
- );
73
-
74
78
// we don't use this, but it's required by the interface to return the list of classes to preload
75
79
return [];
76
80
}
0 commit comments