2
2
3
3
namespace Mcamara \LaravelLocalization \Commands ;
4
4
5
+ use Illuminate \Foundation \Console \RouteCacheCommand ;
5
6
use Mcamara \LaravelLocalization \LaravelLocalization ;
6
7
use Mcamara \LaravelLocalization \Traits \TranslatedRouteCommandContext ;
7
- use Illuminate \Console \Command ;
8
- use Illuminate \Contracts \Console \Kernel ;
9
- use Illuminate \Filesystem \Filesystem ;
10
8
use Illuminate \Routing \RouteCollection ;
11
9
12
- class RouteTranslationsCacheCommand extends Command
10
+ class RouteTranslationsCacheCommand extends RouteCacheCommand
13
11
{
14
12
use TranslatedRouteCommandContext;
15
13
@@ -23,24 +21,6 @@ class RouteTranslationsCacheCommand extends Command
23
21
*/
24
22
protected $ description = 'Create a route cache file for faster route registration for all locales ' ;
25
23
26
- /**
27
- * The filesystem instance.
28
- *
29
- * @var Filesystem
30
- */
31
- protected $ files ;
32
-
33
- /**
34
- * Create a new route command instance.
35
- *
36
- * @param Filesystem $files
37
- */
38
- public function __construct (Filesystem $ files )
39
- {
40
- parent ::__construct ();
41
-
42
- $ this ->files = $ files ;
43
- }
44
24
45
25
/**
46
26
* Execute the console command.
@@ -67,7 +47,7 @@ protected function cacheRoutesPerLocale()
67
47
68
48
foreach ($ allLocales as $ locale ) {
69
49
70
- $ routes = $ this ->getFreshApplicationRoutes ($ locale );
50
+ $ routes = $ this ->getFreshApplicationRoutesForLocale ($ locale );
71
51
72
52
if (count ($ routes ) == 0 ) {
73
53
$ this ->error ("Your application doesn't have any routes. " );
@@ -85,31 +65,27 @@ protected function cacheRoutesPerLocale()
85
65
}
86
66
87
67
/**
88
- * Boot a fresh copy of the application and get the routes.
68
+ * Boot a fresh copy of the application and get the routes for a given locale .
89
69
*
90
70
* @param string|null $locale
91
71
* @return \Illuminate\Routing\RouteCollection
92
72
*/
93
- protected function getFreshApplicationRoutes ($ locale = null )
73
+ protected function getFreshApplicationRoutesForLocale ($ locale = null )
94
74
{
95
- $ app = require $ this ->getBootstrapPath () . '/app.php ' ;
96
-
97
- if (null !== $ locale ) {
98
-
99
- $ key = LaravelLocalization::ENV_ROUTE_KEY ;
75
+ if ($ locale === null ) {
76
+ return $ this ->getFreshApplicationRoutes ();
77
+ }
100
78
101
- putenv ("{$ key }= {$ locale }" );
102
79
103
- $ app -> make (Kernel::class)-> bootstrap () ;
80
+ $ key = LaravelLocalization:: ENV_ROUTE_KEY ;
104
81
105
- putenv ("{$ key }= " );
82
+ putenv ("{$ key }= { $ locale } " );
106
83
107
- } else {
84
+ $ routes = $ this -> getFreshApplicationRoutes ();
108
85
109
- $ app ->make (Kernel::class)->bootstrap ();
110
- }
86
+ putenv ("{$ key }= " );
111
87
112
- return $ app [ ' router ' ]-> getRoutes () ;
88
+ return $ routes ;
113
89
}
114
90
115
91
/**
0 commit comments