|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author jan huang <[email protected]> |
|
4
|
|
|
* @copyright 2016 |
|
5
|
|
|
* |
|
6
|
|
|
* @see https://www.github.com/janhuang |
|
7
|
|
|
* @see https://fastdlabs.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace FastD; |
|
11
|
|
|
|
|
12
|
|
|
use FastD\Console\Config; |
|
13
|
|
|
use FastD\Console\Controller; |
|
14
|
|
|
use FastD\Console\Migration; |
|
15
|
|
|
use FastD\Console\Model; |
|
16
|
|
|
use FastD\Console\Routing; |
|
17
|
|
|
use Symfony\Component\Console\Application as Symfony; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class AppConsole. |
|
23
|
|
|
*/ |
|
24
|
|
|
class Console extends Symfony |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* AppConsole constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param Application $app |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Application $app) |
|
32
|
|
|
{ |
|
33
|
|
|
$version = Application::VERSION; |
|
34
|
|
|
|
|
35
|
|
|
parent::__construct(<<<EOF |
|
36
|
|
|
|
|
37
|
|
|
______ __ ____ |
|
38
|
|
|
/ ____/___ ______/ /_/ __ \ |
|
39
|
|
|
/ /_ / __ `/ ___/ __/ / / / |
|
40
|
|
|
/ __/ / /_/ (__ ) /_/ /_/ / |
|
41
|
|
|
/_/ \__,_/____/\__/_____/ |
|
42
|
|
|
<info>{$version}</info> |
|
43
|
|
|
|
|
44
|
|
|
EOF |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
restore_exception_handler(); |
|
48
|
|
|
|
|
49
|
|
|
$this->registerCommands(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Scan commands. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function registerCommands() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->addCommands([ |
|
58
|
|
|
new Model(), |
|
59
|
|
|
new Controller(), |
|
60
|
|
|
new Routing(), |
|
61
|
|
|
new Config(), |
|
62
|
|
|
new Migration(), |
|
63
|
|
|
]); |
|
64
|
|
|
|
|
65
|
|
|
$consoles = config()->get('consoles', []); |
|
66
|
|
|
$consoles = array_unique($consoles); |
|
67
|
|
|
|
|
68
|
|
|
foreach ($consoles as $console) { |
|
69
|
|
|
$this->add(new $console()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (false !== ($files = glob(app()->getPath().'/src/Console/*.php', GLOB_NOSORT | GLOB_NOESCAPE))) { |
|
73
|
|
|
foreach ($files as $file) { |
|
74
|
|
|
$command = '\\Console\\'.pathinfo($file, PATHINFO_FILENAME); |
|
75
|
|
|
$this->add(new $command()); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param InputInterface $input |
|
82
|
|
|
* @param OutputInterface $output |
|
83
|
|
|
* |
|
84
|
|
|
* @return int |
|
85
|
|
|
* |
|
86
|
|
|
* @throws \Throwable |
|
87
|
|
|
*/ |
|
88
|
|
|
public function doRun(InputInterface $input, OutputInterface $output) |
|
89
|
|
|
{ |
|
90
|
|
|
app()->add('input', $input); |
|
91
|
|
|
app()->add('output', $output); |
|
92
|
|
|
|
|
93
|
|
|
try { |
|
94
|
|
|
return parent::doRun($input, $output); |
|
95
|
|
|
} catch (\Exception $exception) { |
|
96
|
|
|
app()->handleException($exception); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
throw $exception; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|