mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 08:45:40 +08:00
Add custom binary check-update support for artifacts
This commit is contained in:
@@ -30,6 +30,9 @@ class Artifact
|
||||
/** @var array<string, callable> Bind custom binary fetcher callbacks */
|
||||
protected mixed $custom_binary_callbacks = [];
|
||||
|
||||
/** @var array<string, callable> Bind custom binary check-update callbacks */
|
||||
protected array $custom_binary_check_update_callbacks = [];
|
||||
|
||||
/** @var null|callable Bind custom source extract callback (completely takes over extraction) */
|
||||
protected mixed $source_extract_callback = null;
|
||||
|
||||
@@ -433,6 +436,24 @@ class Artifact
|
||||
$this->custom_binary_callbacks[$target_os] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom binary check-update callback for a specific target OS.
|
||||
*
|
||||
* @param string $target_os Target OS platform string (e.g. linux-x86_64)
|
||||
* @param callable $callback Custom binary check-update callback
|
||||
*/
|
||||
public function setCustomBinaryCheckUpdateCallback(string $target_os, callable $callback): void
|
||||
{
|
||||
ConfigValidator::validatePlatformString($target_os);
|
||||
$this->custom_binary_check_update_callbacks[$target_os] = $callback;
|
||||
}
|
||||
|
||||
public function getCustomBinaryCheckUpdateCallback(): ?callable
|
||||
{
|
||||
$current_platform = SystemTarget::getCurrentPlatformString();
|
||||
return $this->custom_binary_check_update_callbacks[$current_platform] ?? null;
|
||||
}
|
||||
|
||||
// ==================== Extraction Callbacks ====================
|
||||
|
||||
/**
|
||||
|
||||
@@ -358,8 +358,13 @@ class ArtifactDownloader
|
||||
/** @var CheckUpdateInterface $downloader */
|
||||
$downloader = new $cls();
|
||||
return $downloader->checkUpdate($artifact_name, $info['config'], $info['version'], $this);
|
||||
}
|
||||
throw new WrongUsageException("Artifact '{$artifact_name}' downloader does not support update checking, exit.");
|
||||
} // custom binary: delegate to registered check-update callback
|
||||
if (($callback = $artifact->getCustomBinaryCheckUpdateCallback()) !== null) {
|
||||
return ApplicationContext::invoke($callback, [
|
||||
ArtifactDownloader::class => $this,
|
||||
'old_version' => $info['version'],
|
||||
]);
|
||||
} throw new WrongUsageException("Artifact '{$artifact_name}' downloader does not support update checking, exit.");
|
||||
}
|
||||
|
||||
public function getRetry(): int
|
||||
|
||||
Reference in New Issue
Block a user