1 | <?php |
||
11 | class PartialParts extends Command |
||
12 | { |
||
13 | /** |
||
14 | * The console command name. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $name = 'partial-parts'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'List all registered routes'; |
||
26 | |||
27 | /** |
||
28 | * The router instance. |
||
29 | * |
||
30 | * @var \Illuminate\Routing\Router |
||
31 | */ |
||
32 | protected $router; |
||
33 | |||
34 | /** |
||
35 | * The table headers for the command. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $headers = ['Domain', 'Method', 'URI', 'Name', 'Action', 'Middleware']; |
||
40 | |||
41 | /** |
||
42 | * The columns to display when using the "compact" flag. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $compactColumns = ['method', 'uri', 'action']; |
||
47 | |||
48 | /** |
||
49 | * Create a new route command instance. |
||
50 | * |
||
51 | * @param \Illuminate\Routing\Router $router |
||
52 | * @return void |
||
|
|||
53 | */ |
||
54 | public function __construct(Router $router) |
||
55 | { |
||
56 | parent::__construct(); |
||
57 | |||
58 | $this->router = $router; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Execute the console command. |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | public function handle() |
||
67 | { |
||
68 | $parts = collect($this->router->getRoutes())->map(function ($route) { |
||
69 | return $this->getPartialPartsMiddleware($route); |
||
70 | })->filter()->unique()->map(function ($route) { |
||
71 | return [$route]; |
||
72 | }); |
||
73 | |||
74 | if ($parts->count() === 0) { |
||
75 | $this->error('No parts found!'); |
||
76 | } else { |
||
77 | $headers = ['Parts in use']; |
||
78 | $this->table($headers, $parts->toArray()); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Get the route information for a given route. |
||
84 | * |
||
85 | * @param \Illuminate\Routing\Route $route |
||
86 | * @return array |
||
87 | */ |
||
88 | protected function getPartialPartsMiddleware(Route $route) |
||
98 | } |
||
99 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.