1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of Laravel Zero. |
7
|
|
|
* |
8
|
|
|
* (c) Nuno Maduro <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace LaravelZero\Framework; |
15
|
|
|
|
16
|
|
|
use function define; |
17
|
|
|
use ReflectionClass; |
18
|
|
|
use function collect; |
19
|
|
|
use function defined; |
20
|
|
|
use function in_array; |
21
|
|
|
use function get_class; |
22
|
|
|
use Illuminate\Console\Application as Artisan; |
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
24
|
|
|
use Illuminate\Foundation\Console\Kernel as BaseKernel; |
25
|
|
|
|
26
|
|
|
class Kernel extends BaseKernel |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* The application's development commands. |
30
|
|
|
* |
31
|
|
|
* @var string[] |
32
|
|
|
*/ |
33
|
|
|
protected $developmentCommands = [ |
34
|
|
|
Commands\BuildCommand::class, |
35
|
|
|
Commands\RenameCommand::class, |
36
|
|
|
Commands\MakeCommand::class, |
37
|
|
|
Commands\InstallCommand::class, |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The application's bootstrap classes. |
42
|
|
|
* |
43
|
|
|
* @var string[] |
44
|
|
|
*/ |
45
|
|
|
protected $bootstrappers = [ |
46
|
|
|
\LaravelZero\Framework\Bootstrap\CoreBindings::class, |
47
|
|
|
\LaravelZero\Framework\Bootstrap\LoadEnvironmentVariables::class, |
48
|
|
|
\LaravelZero\Framework\Bootstrap\LoadConfiguration::class, |
49
|
|
|
\Illuminate\Foundation\Bootstrap\HandleExceptions::class, |
50
|
|
|
\LaravelZero\Framework\Bootstrap\RegisterFacades::class, |
51
|
|
|
\LaravelZero\Framework\Bootstrap\RegisterProviders::class, |
52
|
|
|
\Illuminate\Foundation\Bootstrap\BootProviders::class, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Kernel constructor. |
57
|
|
|
*/ |
58
|
29 |
|
public function __construct( |
59
|
|
|
\Illuminate\Contracts\Foundation\Application $app, |
60
|
|
|
\Illuminate\Contracts\Events\Dispatcher $events |
61
|
|
|
) { |
62
|
29 |
|
if (! defined('ARTISAN_BINARY')) { |
63
|
|
|
define('ARTISAN_BINARY', basename($_SERVER['SCRIPT_FILENAME'])); |
64
|
|
|
} |
65
|
|
|
|
66
|
29 |
|
parent::__construct($app, $events); |
67
|
29 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
1 |
|
public function handle($input, $output = null) |
73
|
|
|
{ |
74
|
1 |
|
$this->app->instance(OutputInterface::class, $output); |
75
|
|
|
|
76
|
1 |
|
return parent::handle($input, $output); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
29 |
|
public function bootstrap(): void |
83
|
|
|
{ |
84
|
29 |
|
parent::bootstrap(); |
85
|
|
|
|
86
|
29 |
|
if ($commandClass = $this->app['config']->get('commands.default')) { |
87
|
29 |
|
$this->getArtisan() |
88
|
29 |
|
->setDefaultCommand( |
89
|
29 |
|
$this->app[$commandClass]->getName() |
90
|
|
|
); |
91
|
|
|
} |
92
|
29 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
29 |
|
protected function commands(): void |
98
|
|
|
{ |
99
|
29 |
|
$config = $this->app['config']; |
100
|
|
|
|
101
|
|
|
/* |
102
|
|
|
* Loads commands paths. |
103
|
|
|
*/ |
104
|
29 |
|
$this->load($config->get('commands.paths', $this->app->path('Commands'))); |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Loads configurated commands. |
108
|
|
|
*/ |
109
|
29 |
|
$commands = collect($config->get('commands.add', []))->merge($config->get('commands.hidden', [])); |
110
|
|
|
|
111
|
29 |
|
if ($command = $config->get('commands.default')) { |
112
|
29 |
|
$commands->push($command); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/* |
116
|
|
|
* Loads development commands. |
117
|
|
|
*/ |
118
|
29 |
|
if ($this->app->environment() !== 'production') { |
119
|
28 |
|
$commands = $commands->merge($this->developmentCommands); |
120
|
|
|
} |
121
|
|
|
|
122
|
29 |
|
$commands = $commands->diff($toRemoveCommands = $config->get('commands.remove', [])); |
123
|
|
|
|
124
|
29 |
|
Artisan::starting( |
125
|
|
|
function ($artisan) use ($toRemoveCommands) { |
126
|
29 |
|
$reflectionClass = new ReflectionClass(Artisan::class); |
127
|
29 |
|
$commands = collect($artisan->all()) |
128
|
29 |
|
->filter( |
129
|
|
|
function ($command) use ($toRemoveCommands) { |
130
|
29 |
|
return ! in_array(get_class($command), $toRemoveCommands, true); |
131
|
29 |
|
} |
132
|
|
|
) |
133
|
29 |
|
->toArray(); |
134
|
|
|
|
135
|
29 |
|
$property = $reflectionClass->getParentClass() |
136
|
29 |
|
->getProperty('commands'); |
137
|
|
|
|
138
|
29 |
|
$property->setAccessible(true); |
139
|
29 |
|
$property->setValue($artisan, $commands); |
140
|
29 |
|
$property->setAccessible(false); |
141
|
29 |
|
} |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
/* |
145
|
|
|
* Registers a bootstrap callback on the artisan console application |
146
|
|
|
* in order to call the schedule method on each Laravel Zero |
147
|
|
|
* command class. |
148
|
|
|
*/ |
149
|
29 |
|
Artisan::starting( |
150
|
|
|
function ($artisan) use ($commands) { |
151
|
29 |
|
$artisan->resolveCommands($commands->toArray()); |
152
|
29 |
|
} |
153
|
|
|
); |
154
|
|
|
|
155
|
29 |
|
Artisan::starting( |
156
|
|
|
function ($artisan) use ($config) { |
157
|
29 |
|
collect($artisan->all())->each( |
158
|
|
|
function ($command) use ($config, $artisan) { |
159
|
29 |
|
if (in_array(get_class($command), $config->get('commands.hidden', []), true)) { |
160
|
29 |
|
$command->setHidden(true); |
161
|
|
|
} |
162
|
|
|
|
163
|
29 |
|
$command->setApplication($artisan); |
164
|
|
|
|
165
|
29 |
|
if ($command instanceof Commands\Command) { |
166
|
29 |
|
$this->app->call([$command, 'schedule']); |
167
|
|
|
} |
168
|
29 |
|
} |
169
|
|
|
); |
170
|
29 |
|
} |
171
|
|
|
); |
172
|
29 |
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Gets the application name. |
176
|
|
|
*/ |
177
|
1 |
|
public function getName(): string |
178
|
|
|
{ |
179
|
1 |
|
return $this->getArtisan() |
180
|
1 |
|
->getName(); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|