Skip to content

Commit d955c6c

Browse files
committed
Fixes artisan commands in web context
1 parent 22fc371 commit d955c6c

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

src/Support/ModuleServiceProvider.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace October\Rain\Support;
22

3+
use Illuminate\Console\Application as Artisan;
34
use October\Contracts\Support\OctoberPackage;
45
use October\Rain\Support\ServiceProvider as ServiceProviderBase;
56

@@ -194,34 +195,35 @@ protected function getModule($args)
194195
*/
195196
protected function discoverConsoleCommands(string $module): void
196197
{
197-
if (!$this->app->runningInConsole()) {
198-
return;
199-
}
200-
201-
$consolePath = base_path('modules/' . $module . '/console');
198+
Artisan::starting(function ($artisan) use ($module) {
199+
$consolePath = base_path('modules/' . $module . '/console');
202200

203-
if (!is_dir($consolePath)) {
204-
return;
205-
}
201+
if (!is_dir($consolePath)) {
202+
return;
203+
}
206204

207-
$namespace = ucfirst($module) . '\\Console\\';
205+
$namespace = ucfirst($module) . '\\Console\\';
206+
$commands = [];
208207

209-
foreach (glob($consolePath . '/*.php') as $file) {
210-
$className = $namespace . basename($file, '.php');
208+
foreach (glob($consolePath . '/*.php') as $file) {
209+
$className = $namespace . basename($file, '.php');
211210

212-
if (!class_exists($className)) {
213-
continue;
214-
}
211+
if (!class_exists($className)) {
212+
continue;
213+
}
215214

216-
$reflection = new \ReflectionClass($className);
215+
$reflection = new \ReflectionClass($className);
217216

218-
if (
219-
$reflection->isSubclassOf(\Illuminate\Console\Command::class) &&
220-
!$reflection->isAbstract()
221-
) {
222-
$this->commands($className);
217+
if (
218+
$reflection->isSubclassOf(\Illuminate\Console\Command::class) &&
219+
!$reflection->isAbstract()
220+
) {
221+
$commands[] = $className;
222+
}
223223
}
224-
}
224+
225+
$artisan->resolveCommands($commands);
226+
});
225227
}
226228

227229
/**

0 commit comments

Comments
 (0)