Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Bow\Console\Command\Generator\GenerateEventListenerCommand;
use Bow\Console\Command\Generator\GenerateTaskCommand;
use Bow\Console\Command\Generator\GenerateRouterResourceCommand;
use Bow\Console\Exception\ConsoleException;

class Command extends AbstractCommand
{
Expand All @@ -40,7 +41,7 @@ class Command extends AbstractCommand
*
* @var array
*/
private array $commands = [
protected static array $commands = [
"clear" => ClearCommand::class,
"seed:file" => SeederCommand::class,
"seed:all" => SeederCommand::class,
Expand Down Expand Up @@ -85,7 +86,24 @@ class Command extends AbstractCommand
*/
public function getCommands(): array
{
return $this->commands;
return static::$commands;
}

/**
* Push new command
*
* @param array $commands
* @return void
*/
public static function pushCommand(array $commands)
{
foreach ($commands as $key => $command) {
if (isset(static::$commands[$key])) {
throw new ConsoleException("$key command already exists");
}

static::$commands[$key] = $command;
}
}

/**
Expand All @@ -99,7 +117,7 @@ public function getCommands(): array
*/
public function call(string $command, string $action, ...$rest): mixed
{
$class = $this->commands[$command] ?? null;
$class = static::$commands[$command] ?? null;

if (is_null($class)) {
$this->throwFailsCommand("The command $command not found !");
Expand Down
23 changes: 20 additions & 3 deletions src/Console/Command/SchedulerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,33 @@ private function getScheduler(): Scheduler
}

/**
* Load the scheduler from kernel
* Load schedules from two sources:
*
* 1. The host app's Kernel::schedules() method (always called).
* 2. A routes/scheduler.php file relative to the app's base directory,
* if present. The file is included so any code it runs against
* Scheduler::getInstance() registers events.
*
* @param Scheduler $scheduler
* @return void
*/
private function loadSchedulerFile(Scheduler $scheduler): void
{
$kernel = Loader::getInstance();
// The Kernel's schedules() hook is optional — only call it if a Loader
// has been configured (e.g. host app booted, integration test). When
// the command is exercised in isolation (unit tests) we still want the
// routes/scheduler.php auto-include below to work.
try {
$kernel = Loader::getInstance();
$kernel->schedules($scheduler);
} catch (\Throwable) {
// No Loader configured; skip the Kernel hook and continue.
}

$kernel->schedules($scheduler);
$routes_file = $this->setting->getBaseDirectory() . '/routes/scheduler.php';
if (is_file($routes_file)) {
require $routes_file;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/SeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function make(string $seed_filename, string $seeder_class_name): void
/**
* Launch targeted seeding
*
* @param string|null $seeder_name
* @param string|null $seeder_class_name
* @return void
*/
public function file(?string $seeder_class_name = null): void
Expand Down
Loading
Loading