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
13 changes: 1 addition & 12 deletions system/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,6 @@ protected static function initializeConsole(): Console

protected static function runCommand(Console $console): int
{
$exitCode = $console->initialize()->run();

if (! is_int($exitCode)) {
@trigger_error(sprintf(
'Since v4.8.0, commands must return an integer exit code. Last command "%s" exited with %s. Defaulting to EXIT_SUCCESS.',
$console->getCommand(),
get_debug_type($exitCode),
), E_USER_DEPRECATED);
$exitCode = EXIT_SUCCESS;
}

return $exitCode;
return $console->initialize()->run();
}
}
4 changes: 2 additions & 2 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function __construct(LoggerInterface $logger, Commands $commands)
*
* @param array<int|string, string|null> $params
*
* @return int|void
* @return int|null
*/
abstract public function run(array $params);

Expand All @@ -110,7 +110,7 @@ abstract public function run(array $params);
*
* @param array<int|string, string|null> $params
*
* @return int|void
* @return int|null
*
* @throws ReflectionException
*/
Expand Down
13 changes: 11 additions & 2 deletions system/CLI/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,20 @@ public function run(string $command, array $params)

Events::trigger('pre_command');

$exit = $class->run($params);
$exitCode = $class->run($params);

Events::trigger('post_command');

return $exit;
if (! is_int($exitCode)) {
@trigger_error(sprintf(
'Since v4.8.0, commands must return an integer exit code. Last command "%s" exited with %s. Defaulting to EXIT_SUCCESS.',
$command,
get_debug_type($exitCode),
), E_USER_DEPRECATED);
$exitCode = EXIT_SUCCESS;
}

return $exitCode;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CLI/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Console
*
* @param list<string> $tokens
*
* @return int|null Exit code or null for legacy commands that don't return an exit code.
* @return int Exit code
*/
public function run(array $tokens = [])
{
Expand Down
4 changes: 3 additions & 1 deletion system/Commands/Cache/InfoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function run(array $params)
if ($config->handler !== 'file') {
CLI::error('This command only supports the file cache handler.');

return;
return EXIT_ERROR;
}

$cache = CacheFactory::getHandler($config);
Expand All @@ -87,5 +87,7 @@ public function run(array $params)
];

CLI::table($tbody, $thead);

return EXIT_SUCCESS;
}
}
10 changes: 7 additions & 3 deletions system/Commands/Database/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function run(array $params)
CLI::error("Database \"{$dbName}\" already exists.", 'light_gray', 'red');
CLI::newLine();

return;
return EXIT_ERROR;
}

unset($dbName);
Expand All @@ -130,22 +130,26 @@ public function run(array $params)
CLI::error('Database creation failed.', 'light_gray', 'red');
CLI::newLine();

return;
return EXIT_ERROR;
// @codeCoverageIgnoreEnd
}
} elseif (! Database::forge()->createDatabase($name)) {
// @codeCoverageIgnoreStart
CLI::error('Database creation failed.', 'light_gray', 'red');
CLI::newLine();

return;
return EXIT_ERROR;
// @codeCoverageIgnoreEnd
}

CLI::write("Database \"{$name}\" successfully created.", 'green');
CLI::newLine();

return EXIT_SUCCESS;
} catch (Throwable $e) {
$this->showError($e);

return EXIT_ERROR;
} finally {
Factories::reset('config');
Database::connect(null, false);
Expand Down
3 changes: 3 additions & 0 deletions system/Commands/Database/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ public function run(array $params)

CLI::write(lang('Migrations.migrated'), 'green');

return EXIT_SUCCESS;
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
$this->showError($e);

return EXIT_ERROR;
// @codeCoverageIgnoreEnd
}
}
Expand Down
9 changes: 4 additions & 5 deletions system/Commands/Database/MigrateRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,15 @@ public function run(array $params)
$force = array_key_exists('f', $params) || CLI::getOption('f');

if (! $force && CLI::prompt(lang('Migrations.refreshConfirm'), ['y', 'n']) === 'n') {
return;
return EXIT_ERROR;
}

$params['f'] = null;
// @codeCoverageIgnoreEnd
}

$this->withSignalsBlocked(function () use ($params): void {
$this->call('migrate:rollback', $params);
$this->call('migrate', $params);
});
return $this->withSignalsBlocked(
fn (): int => $this->call('migrate:rollback', $params) | $this->call('migrate', $params),
);
}
}
17 changes: 13 additions & 4 deletions system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function run(array $params)
$force = array_key_exists('f', $params) || CLI::getOption('f');

if (! $force && CLI::prompt(lang('Migrations.rollBackConfirm'), ['y', 'n']) === 'n') {
return null;
return EXIT_ERROR;
}
// @codeCoverageIgnoreEnd
}
Expand All @@ -101,12 +101,20 @@ public function run(array $params)

CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

$this->withSignalsBlocked(static function () use ($runner, $batch): void {
$exit = $this->withSignalsBlocked(static function () use ($runner, $batch): int {
if (! $runner->regress($batch)) {
CLI::error(lang('Migrations.generalFault'), 'light_gray', 'red'); // @codeCoverageIgnore

return EXIT_ERROR;
}

return EXIT_SUCCESS;
});

if ($exit !== EXIT_SUCCESS) {
return $exit;
}

$messages = $runner->getCliMessages();

foreach ($messages as $message) {
Expand All @@ -115,12 +123,13 @@ public function run(array $params)

CLI::write('Done rolling back migrations.', 'green');

return EXIT_SUCCESS;
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
$this->showError($e);

return EXIT_ERROR;
// @codeCoverageIgnoreEnd
}

return null;
}
}
4 changes: 3 additions & 1 deletion system/Commands/Database/MigrateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function run(array $params)
CLI::error(lang('Migrations.noneFound'), 'light_gray', 'red');
CLI::newLine();

return;
return EXIT_ERROR;
// @codeCoverageIgnoreEnd
}

Expand All @@ -164,5 +164,7 @@ public function run(array $params)
];

CLI::table($status, $headers);

return EXIT_SUCCESS;
}
}
4 changes: 4 additions & 0 deletions system/Commands/Database/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ public function run(array $params)

try {
$seeder->call($seedName);

return EXIT_SUCCESS;
} catch (Throwable $e) {
$this->showError($e);

return EXIT_ERROR;
}
}
}
6 changes: 4 additions & 2 deletions system/Commands/Encryption/GenerateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ public function run(array $params)
CLI::write($encodedKey, 'yellow');
CLI::newLine();

return;
return EXIT_SUCCESS;
}

if (! $this->setNewEncryptionKey($encodedKey, $params)) {
CLI::write('Error in setting new encryption key to .env file.', 'light_gray', 'red');
CLI::newLine();

return;
return EXIT_ERROR;
}

// force DotEnv to reload the new env vars
Expand All @@ -107,6 +107,8 @@ public function run(array $params)

CLI::write('Application\'s new encryption key was successfully set.', 'green');
CLI::newLine();

return EXIT_SUCCESS;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Generators/CellGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ public function run(array $params)

$this->generateView($namespace . $viewName, $params);

return 0;
return EXIT_SUCCESS;
}
}
2 changes: 2 additions & 0 deletions system/Commands/Generators/CommandGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.command';
$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions system/Commands/Generators/ConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.config';
$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions system/Commands/Generators/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.controller';
$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions system/Commands/Generators/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.entity';
$this->generateClass($params);

return EXIT_SUCCESS;
}
}
2 changes: 2 additions & 0 deletions system/Commands/Generators/FilterGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.filter';
$this->generateClass($params);

return EXIT_SUCCESS;
}
}
2 changes: 2 additions & 0 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.migration';
$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions system/Commands/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.model';
$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions system/Commands/Generators/ScaffoldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ public function run(array $params)
$class = $params[0] ?? CLI::getSegment(2);

// Call those commands!
$this->call('make:controller', array_merge([$class], $controllerOpts, $options));
$this->call('make:model', array_merge([$class], $modelOpts, $options));
$this->call('make:migration', array_merge([$class], $options));
$this->call('make:seeder', array_merge([$class], $options));
$exit1 = $this->call('make:controller', array_merge([$class], $controllerOpts, $options));
$exit2 = $this->call('make:model', array_merge([$class], $modelOpts, $options));
$exit3 = $this->call('make:migration', array_merge([$class], $options));
$exit4 = $this->call('make:seeder', array_merge([$class], $options));

assert(is_int($exit1) && is_int($exit2) && is_int($exit3) && is_int($exit4));

return $exit1 | $exit2 | $exit3 | $exit4;
}
}
2 changes: 2 additions & 0 deletions system/Commands/Generators/SeederGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.seeder';
$this->generateClass($params);

return EXIT_SUCCESS;
}
}
2 changes: 2 additions & 0 deletions system/Commands/Generators/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function run(array $params)
$autoload->addNamespace('Tests', ROOTPATH . 'tests');

$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions system/Commands/Generators/TransformerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.transformer';
$this->generateClass($params);

return EXIT_SUCCESS;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions system/Commands/Generators/ValidationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ public function run(array $params)

$this->classNameLang = 'CLI.generator.className.validation';
$this->generateClass($params);

return EXIT_SUCCESS;
}
}
6 changes: 4 additions & 2 deletions system/Commands/Generators/Views/command.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public function run(array $params)
$this->directory = 'Commands';
$this->template = 'command.tpl.php';

$this->execute($params);
$this->generateClass($params);
<?php else: ?>
//
// your command logic here
<?php endif ?>

return EXIT_SUCCESS;
}
}
Loading
Loading