@@ -96,6 +96,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9696 }
9797 $ asJson = $ outputMode === OutputMode::JSON ;
9898
99+ // Prime exit-code constants before any self-replacement so the current
100+ // process never needs to autoload ExitCode from a swapped archive.
101+ $ successExit = ExitCode::SUCCESS ;
102+ $ failureExit = ExitCode::FAILURE ;
103+
99104 $ target = $ this ->detector !== null ? ($ this ->detector )() : InstallationTarget::detect (
100105 argv0: (string ) ($ _SERVER ['argv ' ][0 ] ?? '' ),
101106 pharRunning: \Phar::running (false ),
@@ -122,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
122127 'installation ' => $ target ->toArray (),
123128 'current_version ' => $ currentVersion ,
124129 'target_version ' => null ,
125- ], ExitCode:: FAILURE );
130+ ], $ failureExit );
126131 }
127132
128133 $ catalog = $ this ->catalog ?? ReleaseCatalog::create ();
@@ -136,7 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
136141 'installation ' => $ target ->toArray (),
137142 'current_version ' => $ currentVersion ,
138143 'target_version ' => null ,
139- ], ExitCode:: FAILURE );
144+ ], $ failureExit );
140145 }
141146
142147 if ($ target ->assetName === null ) {
@@ -146,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146151 'installation ' => $ target ->toArray (),
147152 'current_version ' => $ currentVersion ,
148153 'target_version ' => $ targetVersion ,
149- ], ExitCode:: FAILURE );
154+ ], $ failureExit );
150155 }
151156
152157 $ sameVersion = $ this ->versionsMatch ($ currentVersion , $ targetVersion );
@@ -158,7 +163,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
158163 'installation ' => $ target ->toArray (),
159164 'current_version ' => $ currentVersion ,
160165 'target_version ' => $ targetVersion ,
161- ], ExitCode:: SUCCESS );
166+ ], $ successExit );
162167 }
163168
164169 $ binaryUrl = $ catalog ->downloadUrl ($ targetVersion , $ target ->assetName );
@@ -172,7 +177,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
172177 'target_version ' => $ targetVersion ,
173178 'asset_url ' => $ binaryUrl ,
174179 'checksum_url ' => $ sumsUrl ,
175- ], ExitCode:: SUCCESS );
180+ ], $ successExit );
176181 }
177182
178183 if (! $ target ->upgradeable ) {
@@ -182,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
182187 'installation ' => $ target ->toArray (),
183188 'current_version ' => $ currentVersion ,
184189 'target_version ' => $ targetVersion ,
185- ], ExitCode:: FAILURE );
190+ ], $ failureExit );
186191 }
187192
188193 try {
@@ -196,7 +201,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
196201 'installation ' => $ target ->toArray (),
197202 'current_version ' => $ currentVersion ,
198203 'target_version ' => $ targetVersion ,
199- ], ExitCode:: FAILURE );
204+ ], $ failureExit );
200205 }
201206
202207 $ actual = hash ('sha256 ' , $ binary );
@@ -207,7 +212,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
207212 'installation ' => $ target ->toArray (),
208213 'current_version ' => $ currentVersion ,
209214 'target_version ' => $ targetVersion ,
210- ], ExitCode:: FAILURE );
215+ ], $ failureExit );
211216 }
212217
213218 $ replacer = $ this ->replacer ?? self ::defaultReplacer (...);
@@ -221,23 +226,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
221226 'installation ' => $ target ->toArray (),
222227 'current_version ' => $ currentVersion ,
223228 'target_version ' => $ targetVersion ,
224- ], ExitCode:: FAILURE );
229+ ], $ failureExit );
225230 } catch (\RuntimeException $ e ) {
226231 return $ this ->emit ($ output , $ asJson , [
227232 'status ' => 'error ' ,
228233 'reason ' => $ e ->getMessage (),
229234 'installation ' => $ target ->toArray (),
230235 'current_version ' => $ currentVersion ,
231236 'target_version ' => $ targetVersion ,
232- ], ExitCode:: FAILURE );
237+ ], $ failureExit );
233238 }
234239
235240 return $ this ->emit ($ output , $ asJson , [
236241 'status ' => 'upgraded ' ,
237242 'installation ' => $ target ->toArray (),
238243 'current_version ' => $ currentVersion ,
239244 'target_version ' => $ targetVersion ,
240- ], ExitCode:: SUCCESS );
245+ ], $ successExit );
241246 }
242247
243248 private function emit (OutputInterface $ output , bool $ asJson , array $ payload , int $ exit ): int
0 commit comments