|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RichanFongdasen\I18n\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Console\Kernel; |
|
6
|
|
|
use Illuminate\Foundation\Console\RouteListCommand; |
|
7
|
|
|
use RichanFongdasen\I18n\Traits\TranslatedRouteCommandContext; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
|
|
10
|
|
|
class RouteTranslationsListCommand extends RouteListCommand |
|
11
|
|
|
{ |
|
12
|
|
|
use TranslatedRouteCommandContext; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $name = 'route:trans:list'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $description = 'List all registered routes for specific locales'; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Execute the console command. |
|
27
|
|
|
*/ |
|
28
|
|
View Code Duplication |
public function handle() |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
if (count($this->routes) == 0) { |
|
|
|
|
|
|
31
|
|
|
$this->error("Your application doesn't have any routes."); |
|
32
|
|
|
return; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$locale = $this->argument('locale'); |
|
36
|
|
|
|
|
37
|
|
|
if ( ! $this->isSupportedLocale($locale)) { |
|
|
|
|
|
|
38
|
|
|
$this->error("Unsupported locale: '{$locale}'."); |
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->routes = $this->getFreshApplicationRoutes($locale); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$this->displayRoutes($this->getRoutes()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Boot a fresh copy of the application and get the routes. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $locale |
|
51
|
|
|
* @return \Illuminate\Routing\RouteCollection |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function getFreshApplicationRoutes($locale) |
|
54
|
|
|
{ |
|
55
|
|
|
$app = require $this->getBootstrapPath() . '/app.php'; |
|
56
|
|
|
|
|
57
|
|
|
$default = config('i18n.fallback_language'); |
|
58
|
|
|
|
|
59
|
|
|
config(['i18n.fallback_language' => $locale]); |
|
60
|
|
|
|
|
61
|
|
|
$app->make(Kernel::class)->bootstrap(); |
|
62
|
|
|
|
|
63
|
|
|
config(['i18n.fallback_language' => $default]); |
|
64
|
|
|
|
|
65
|
|
|
return $app['router']->getRoutes(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the console command arguments. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
|
|
|
|
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getArguments() |
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
['locale', InputArgument::REQUIRED, 'The locale to list routes for.'], |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.