-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRouteScanCommand.php
More file actions
97 lines (81 loc) · 2.13 KB
/
RouteScanCommand.php
File metadata and controls
97 lines (81 loc) · 2.13 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace ProAI\Annotations\Console;
use Illuminate\Console\Command;
use ProAI\Annotations\Metadata\ClassFinder;
use ProAI\Annotations\Metadata\RouteScanner;
use ProAI\Annotations\Routing\Generator;
class RouteScanCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'route:scan';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scan all routes with route annotations.';
/**
* The class finder instance.
*
* @var \ProAI\Annotations\Metadata\ClassFinder
*/
protected $finder;
/**
* The route scanner instance.
*
* @var \ProAI\Annotations\Metadata\RouteScanner
*/
protected $scanner;
/**
* The routes generator instance.
*
* @var \ProAI\Annotations\Routing\Generator
*/
protected $generator;
/**
* The config of the route annotations package.
*
* @var array
*/
protected $config;
/**
* Create a new migration install command instance.
*
* @param \ProAI\Annotations\Metadata\ClassFinder $finder
* @param \ProAI\Annotations\Metadata\RouteScanner $scanner
* @param \ProAI\Annotations\Routing\Generator $generator
* @param array $config
* @return void
*/
public function __construct(ClassFinder $finder, RouteScanner $scanner, Generator $generator, $config)
{
parent::__construct();
$this->finder = $finder;
$this->scanner = $scanner;
$this->generator = $generator;
$this->config = $config;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// get classes
$classes = $this->finder->getClassesFromNamespace($this->config['routes_namespace']);
// build metadata
$routes = $this->scanner->scan($classes);
// generate routes.php file for scanned routes
$this->generator->generate($routes);
$this->info('Routes registered successfully!');
}
public function handle()
{
$this->fire();
}
}