55namespace Php \Pie \Command ;
66
77use Composer \IO \IOInterface ;
8+ use Composer \IO \NullIO ;
9+ use Php \Pie \ComposerIntegration \PieComposerFactory ;
10+ use Php \Pie \ComposerIntegration \PieComposerRequest ;
11+ use Php \Pie \ComposerIntegration \QuieterConsoleIO ;
812use Php \Pie \File \BinaryFile ;
913use Php \Pie \File \FullPathToSelf ;
14+ use Php \Pie \SelfManage \Update \FetchPieReleaseFromGitHub ;
1015use Php \Pie \SelfManage \Update \ReleaseMetadata ;
1116use Php \Pie \SelfManage \Verify \FailedToVerifyRelease ;
1217use Php \Pie \SelfManage \Verify \VerifyPieReleaseUsingAttestation ;
1318use Php \Pie \Util \Emoji ;
1419use Php \Pie \Util \PieVersion ;
20+ use Psr \Container \ContainerInterface ;
1521use Symfony \Component \Console \Attribute \AsCommand ;
1622use Symfony \Component \Console \Command \Command ;
23+ use Symfony \Component \Console \Input \InputArgument ;
1724use Symfony \Component \Console \Input \InputInterface ;
1825use Symfony \Component \Console \Output \OutputInterface ;
1926
2532)]
2633final class SelfVerifyCommand extends Command
2734{
35+ private const ARGUMENT_VERSION = 'version ' ;
36+
37+ /** @param non-empty-string $githubApiBaseUrl */
2838 public function __construct (
39+ private readonly string $ githubApiBaseUrl ,
2940 private readonly FullPathToSelf $ fullPathToSelf ,
3041 private readonly IOInterface $ io ,
42+ private readonly QuieterConsoleIO $ quieterConsoleIo ,
43+ private readonly ContainerInterface $ container ,
3144 ) {
3245 parent ::__construct ();
3346 }
@@ -37,6 +50,11 @@ public function configure(): void
3750 parent ::configure ();
3851
3952 CommandHelper::configurePhpConfigOptions ($ this );
53+ $ this ->addArgument (
54+ self ::ARGUMENT_VERSION ,
55+ InputArgument::OPTIONAL ,
56+ 'The version of PIE you expect to be running (e.g. 1.4.4 or nightly) ' ,
57+ );
4058 }
4159
4260 public function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -47,15 +65,40 @@ public function execute(InputInterface $input, OutputInterface $output): int
4765 return Command::FAILURE ;
4866 }
4967
50- $ latestRelease = new ReleaseMetadata (PieVersion::get (), 'blah ' );
68+ $ expectedVersion = (string ) $ input ->getArgument (self ::ARGUMENT_VERSION );
69+
70+ if ($ expectedVersion === '' ) {
71+ $ expectedVersion = PieVersion::get ();
72+ $ this ->io ->write (sprintf ('<comment>No version specified, verifying against the version this PHAR claims to be (%s).</comment> ' , $ expectedVersion ));
73+ }
74+
75+ $ targetPlatform = CommandHelper::determineTargetPlatformFromInputs ($ input , $ this ->io );
76+
77+ CommandHelper::applyNoCacheOptionIfSet ($ input , $ this ->io );
78+
79+ $ composer = PieComposerFactory::createPieComposer (
80+ $ this ->container ,
81+ PieComposerRequest::noOperation (
82+ new NullIO (),
83+ $ targetPlatform ,
84+ ),
85+ );
86+
87+ $ fetchLatestPieRelease = FetchPieReleaseFromGitHub::factory (
88+ $ this ->quieterConsoleIo ,
89+ $ composer ->getConfig (),
90+ $ this ->githubApiBaseUrl ,
91+ );
92+
93+ $ latestRelease = new ReleaseMetadata ($ expectedVersion , 'blah ' );
5194 $ pharFilename = BinaryFile::fromFileWithSha256Checksum (($ this ->fullPathToSelf )());
52- $ verifyPiePhar = VerifyPieReleaseUsingAttestation::factory ();
95+ $ verifyPiePhar = VerifyPieReleaseUsingAttestation::factory ($ fetchLatestPieRelease );
5396
5497 try {
5598 $ verifyPiePhar ->verify ($ latestRelease , $ pharFilename , $ this ->io );
5699 } catch (FailedToVerifyRelease $ failedToVerifyRelease ) {
57100 $ this ->io ->writeError (sprintf (
58- '<error>❌ Failed to verify the pie.phar release %s: %s</error> ' ,
101+ '<error>❌ Failed to verify that this PIE binary is the authentic release %s: %s</error> ' ,
59102 $ latestRelease ->tag ,
60103 $ failedToVerifyRelease ->getMessage (),
61104 ));
@@ -64,7 +107,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
64107 }
65108
66109 $ this ->io ->write (sprintf (
67- '<info>%s You are running an authentic PIE version %s.</info> ' ,
110+ '<info>%s This is an authentic PIE release for version %s.</info> ' ,
68111 Emoji::GREEN_CHECKMARK ,
69112 $ latestRelease ->tag ,
70113 ));
0 commit comments