2025-11-30 15:35:04 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace StaticPHP;
|
|
|
|
|
|
|
|
|
|
use StaticPHP\Command\BuildLibsCommand;
|
|
|
|
|
use StaticPHP\Command\BuildTargetCommand;
|
2025-12-11 11:35:12 +08:00
|
|
|
use StaticPHP\Command\Dev\EnvCommand;
|
2025-12-08 10:36:45 +08:00
|
|
|
use StaticPHP\Command\Dev\IsInstalledCommand;
|
|
|
|
|
use StaticPHP\Command\Dev\ShellCommand;
|
2025-12-18 15:43:58 +08:00
|
|
|
use StaticPHP\Command\Dev\SortConfigCommand;
|
2025-11-30 15:35:04 +08:00
|
|
|
use StaticPHP\Command\DoctorCommand;
|
|
|
|
|
use StaticPHP\Command\DownloadCommand;
|
2026-01-22 16:04:48 +08:00
|
|
|
use StaticPHP\Command\DumpLicenseCommand;
|
2025-11-30 15:35:04 +08:00
|
|
|
use StaticPHP\Command\ExtractCommand;
|
|
|
|
|
use StaticPHP\Command\InstallPackageCommand;
|
|
|
|
|
use StaticPHP\Command\SPCConfigCommand;
|
|
|
|
|
use StaticPHP\Package\TargetPackage;
|
2025-12-09 14:58:11 +08:00
|
|
|
use StaticPHP\Registry\PackageLoader;
|
|
|
|
|
use StaticPHP\Registry\Registry;
|
2025-11-30 15:35:04 +08:00
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
|
|
|
|
|
|
class ConsoleApplication extends Application
|
|
|
|
|
{
|
|
|
|
|
public const string VERSION = '3.0.0-dev';
|
|
|
|
|
|
|
|
|
|
private static array $additional_commands = [];
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2025-12-15 17:00:20 +08:00
|
|
|
parent::__construct('StaticPHP', self::VERSION);
|
2025-11-30 15:35:04 +08:00
|
|
|
|
|
|
|
|
require_once ROOT_DIR . '/src/bootstrap.php';
|
|
|
|
|
|
2025-12-15 17:00:20 +08:00
|
|
|
// resolve registry
|
|
|
|
|
Registry::resolve();
|
2025-12-09 14:58:11 +08:00
|
|
|
|
2025-11-30 15:35:04 +08:00
|
|
|
/**
|
|
|
|
|
* @var string $name
|
|
|
|
|
* @var TargetPackage $package
|
|
|
|
|
*/
|
|
|
|
|
foreach (PackageLoader::getPackages(['target', 'virtual-target']) as $name => $package) {
|
|
|
|
|
// only add target that contains artifact.source
|
|
|
|
|
if ($package->hasStage('build')) {
|
|
|
|
|
logger()->debug("Registering build target command for package: {$name}");
|
2025-12-04 10:53:49 +08:00
|
|
|
$this->addCommand(new BuildTargetCommand($name));
|
2025-11-30 15:35:04 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-04 10:53:49 +08:00
|
|
|
// add core commands
|
2025-11-30 15:35:04 +08:00
|
|
|
$this->addCommands([
|
|
|
|
|
new DownloadCommand(),
|
|
|
|
|
new DoctorCommand(),
|
|
|
|
|
new InstallPackageCommand(),
|
|
|
|
|
new BuildLibsCommand(),
|
|
|
|
|
new ExtractCommand(),
|
|
|
|
|
new SPCConfigCommand(),
|
2026-01-22 16:04:48 +08:00
|
|
|
new DumpLicenseCommand(),
|
2025-12-08 10:36:45 +08:00
|
|
|
|
|
|
|
|
// dev commands
|
|
|
|
|
new ShellCommand(),
|
|
|
|
|
new IsInstalledCommand(),
|
2025-12-11 11:35:12 +08:00
|
|
|
new EnvCommand(),
|
2025-12-18 15:43:58 +08:00
|
|
|
new SortConfigCommand(),
|
2025-11-30 15:35:04 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// add additional commands from registries
|
|
|
|
|
if (!empty(self::$additional_commands)) {
|
|
|
|
|
$this->addCommands(self::$additional_commands);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
public static function _addAdditionalCommands(array $additional_commands): void
|
|
|
|
|
{
|
|
|
|
|
self::$additional_commands = array_merge(self::$additional_commands, $additional_commands);
|
|
|
|
|
}
|
|
|
|
|
}
|