trust filesystem, not downloads

This commit is contained in:
henderkes
2026-05-12 10:38:33 +07:00
parent 270e2d6471
commit c1c34d8c10
4 changed files with 48 additions and 2 deletions

View File

@@ -44,6 +44,9 @@ class CraftCommand extends BaseCommand
// apply env
array_walk($craft['extra-env'], fn ($v, $k) => f_putenv("{$k}={$v}"));
// stash craft for doctor checks that depend on what's being built (e.g. frankenphp → go-xcaddy)
ApplicationContext::set('craft', $craft);
// run doctor
if ($craft['craft-options']['doctor']) {
$doctor = new Doctor($this->output, FIX_POLICY_AUTOFIX);

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Doctor\Item;
use StaticPHP\Attribute\Doctor\CheckItem;
use StaticPHP\Attribute\Doctor\FixItem;
use StaticPHP\Attribute\Doctor\OptionalCheck;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Doctor\CheckResult;
use StaticPHP\Package\PackageInstaller;
#[OptionalCheck([self::class, 'optionalCheck'])]
class GoXcaddyCheck
{
public static function optionalCheck(): bool
{
if (!ApplicationContext::has('craft')) {
return false;
}
$craft = ApplicationContext::get('craft');
return in_array('frankenphp', $craft['sapi'] ?? [], true);
}
#[CheckItem('if go-xcaddy is installed', level: 800)]
public function check(): CheckResult
{
if (!new PackageInstaller()->addInstallPackage('go-xcaddy')->isPackageInstalled('go-xcaddy')) {
return CheckResult::fail('go-xcaddy is not installed', 'install-go-xcaddy');
}
return CheckResult::ok(PKG_ROOT_PATH . '/go-xcaddy/bin/xcaddy');
}
#[FixItem('install-go-xcaddy')]
public function installGoXcaddy(): bool
{
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('go-xcaddy');
$installer->run(true);
return $installer->isPackageInstalled('go-xcaddy');
}
}

View File

@@ -26,7 +26,7 @@ class ZigCheck
public function checkZig(): CheckResult
{
if (new PackageInstaller()->addInstallPackage('zig')->isPackageInstalled('zig')) {
return CheckResult::ok();
return CheckResult::ok(PKG_ROOT_PATH . '/zig/zig');
}
return CheckResult::fail('zig is not installed', 'install-zig');
}

View File

@@ -344,7 +344,7 @@ class PackageInstaller
if ($this->isBuildPackage($package)) {
return $package->isInstalled();
}
if ($package->getArtifact() !== null && $package->getArtifact()->shouldUseBinary()) {
if ($package->getArtifact() !== null && $package->getArtifact()->hasPlatformBinary()) {
$artifact = $package->getArtifact();
return $artifact->isBinaryExtracted();
}