<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Nwidart\Modules\Facades\Module as ModuleManager;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $this->modules($schedule);
    }

    /**
     * 要执行任务的位置增加Console\Kernel类
     * 类中 runCommand(Schedule $schedule)
     * 模型中的command在模型的ServiceProvider自行注册
     *
     * @param  Schedule  $schedule
     */
    protected function modules(Schedule $schedule)
    {
        $data = ModuleManager::toCollection();
        foreach ($data as $name => $module) {
            $class = "\\Modules\\$name\\Console\\Kernel";
            if (class_exists($class)) {
                $runKernel = resolve($class);
                $runKernel->runCommand($schedule);
            }
        }
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        // $this->load(__DIR__.'/Commands');
    }

}
