2023-03-15 20:40:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC;
|
|
|
|
|
|
|
|
|
|
use SPC\store\FileSystem;
|
|
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
|
use Symfony\Component\Console\Command\HelpCommand;
|
|
|
|
|
use Symfony\Component\Console\Command\ListCommand;
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-20 19:51:45 +08:00
|
|
|
* static-php-cli console app entry
|
2023-03-15 20:40:49 +08:00
|
|
|
*/
|
|
|
|
|
class ConsoleApplication extends Application
|
|
|
|
|
{
|
2023-09-08 22:03:40 +08:00
|
|
|
public const VERSION = '2.0-rc6';
|
2023-03-15 20:40:49 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws \ReflectionException
|
|
|
|
|
* @throws exception\FileSystemException
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct('static-php-cli', self::VERSION);
|
|
|
|
|
|
|
|
|
|
global $argv;
|
|
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
// Detailed debugging errors are not displayed in the production environment. Only the error display provided by Symfony console is used.
|
2023-03-15 20:40:49 +08:00
|
|
|
$this->setCatchExceptions(file_exists(ROOT_DIR . '/.prod') || !in_array('--debug', $argv));
|
|
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
// Add subcommands by scanning the directory src/static-php-cli/command/
|
2023-03-15 20:40:49 +08:00
|
|
|
$commands = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/command', 'SPC\\command');
|
2023-08-08 19:22:22 +08:00
|
|
|
$phar = class_exists('\\Phar') && \Phar::running() || !class_exists('\\Phar');
|
|
|
|
|
$commands = array_filter($commands, function ($y) use ($phar) {
|
|
|
|
|
$archive_blacklist = [
|
|
|
|
|
'SPC\command\dev\SortConfigCommand',
|
|
|
|
|
'SPC\command\DeployCommand',
|
|
|
|
|
];
|
|
|
|
|
if ($phar && in_array($y, $archive_blacklist)) {
|
2023-03-15 20:40:49 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$reflection = new \ReflectionClass($y);
|
|
|
|
|
return !$reflection->isAbstract() && !$reflection->isInterface();
|
2023-08-08 19:22:22 +08:00
|
|
|
});
|
|
|
|
|
$this->addCommands(array_map(function ($x) { return new $x(); }, $commands));
|
2023-03-15 20:40:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getDefaultCommands(): array
|
|
|
|
|
{
|
|
|
|
|
return [new HelpCommand(), new ListCommand()];
|
|
|
|
|
}
|
|
|
|
|
}
|