@@ -37,6 +37,7 @@ ${runtimeEnvPhp(spec, args)}
3737${ secretEnvPhp ( spec ) }
3838${ componentManifestPhp ( spec ) }
3939require_once '/wordpress/wp-load.php';
40+ ${ failureDiagnosticFile ? phpFailureDiagnosticCompletionPhp ( ) : "" }
4041${ recipeActivePluginBootstrapPhp ( spec , args ) }
4142${ wpCliBridge ? `putenv(${ JSON . stringify ( `WP_CODEBOX_TERMINAL_ACTION_URL=${ wpCliBridge . url } ` ) } );
4243putenv(${ JSON . stringify ( `WP_CODEBOX_TERMINAL_ACTION_TOKEN=${ wpCliBridge . token } ` ) } );
@@ -45,15 +46,46 @@ ${command.body}`
4546}
4647
4748function phpFailureDiagnosticFilePhp ( path : string ) : string {
48- return `register_shutdown_function(static function (): void {
49- $wp_codebox_failure = error_get_last();
50- if (!is_array($wp_codebox_failure) || !in_array($wp_codebox_failure['type'] ?? 0, array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR), true)) {
49+ return `$wp_codebox_bootstrap_complete = false;
50+ $wp_codebox_bootstrap_buffer_level = ob_get_level();
51+ ob_start();
52+ register_shutdown_function(static function () use (&$wp_codebox_bootstrap_complete, $wp_codebox_bootstrap_buffer_level): void {
53+ if ($wp_codebox_bootstrap_complete) {
5154 return;
5255 }
53- @file_put_contents(${ JSON . stringify ( path ) } , 'STAGE_FATAL:bootstrap:' . (string) ($wp_codebox_failure['message'] ?? '') . ' at ' . (string) ($wp_codebox_failure['file'] ?? '') . ':' . (int) ($wp_codebox_failure['line'] ?? 0) . "\\n", FILE_APPEND);
56+ $wp_codebox_bootstrap_output = '';
57+ while (ob_get_level() > $wp_codebox_bootstrap_buffer_level) {
58+ $wp_codebox_bootstrap_chunk = ob_get_clean();
59+ if ($wp_codebox_bootstrap_chunk !== false) {
60+ $wp_codebox_bootstrap_output = $wp_codebox_bootstrap_chunk . $wp_codebox_bootstrap_output;
61+ }
62+ }
63+ $wp_codebox_failure = error_get_last();
64+ if (is_array($wp_codebox_failure) && in_array($wp_codebox_failure['type'] ?? 0, array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR), true)) {
65+ $wp_codebox_bootstrap_diagnostic = 'STAGE_FATAL:bootstrap:' . (string) ($wp_codebox_failure['message'] ?? '') . ' at ' . (string) ($wp_codebox_failure['file'] ?? '') . ':' . (int) ($wp_codebox_failure['line'] ?? 0);
66+ } else {
67+ $wp_codebox_bootstrap_detail = trim((string) preg_replace('/\\s+/', ' ', strip_tags($wp_codebox_bootstrap_output)));
68+ if ($wp_codebox_bootstrap_detail === '') {
69+ $wp_codebox_bootstrap_detail = 'WordPress bootstrap terminated before completion without emitting output';
70+ }
71+ $wp_codebox_bootstrap_diagnostic = 'STAGE_DIE:bootstrap:' . substr($wp_codebox_bootstrap_detail, 0, 16384);
72+ }
73+ @file_put_contents(${ JSON . stringify ( path ) } , $wp_codebox_bootstrap_diagnostic . "\\n", FILE_APPEND);
5474});`
5575}
5676
77+ function phpFailureDiagnosticCompletionPhp ( ) : string {
78+ return `$wp_codebox_bootstrap_complete = true;
79+ $wp_codebox_bootstrap_output = '';
80+ while (ob_get_level() > $wp_codebox_bootstrap_buffer_level) {
81+ $wp_codebox_bootstrap_chunk = ob_get_clean();
82+ if ($wp_codebox_bootstrap_chunk !== false) {
83+ $wp_codebox_bootstrap_output = $wp_codebox_bootstrap_chunk . $wp_codebox_bootstrap_output;
84+ }
85+ }
86+ echo $wp_codebox_bootstrap_output;`
87+ }
88+
5789export function splitLeadingStrictTypesDeclare ( code : string ) : { strictTypesDeclare : string ; body : string } {
5890 const normalized = normalizePhpCode ( code )
5991 const match = normalized . match ( / ^ < \? p h p \s * ( d e c l a r e \s * \( \s * s t r i c t _ t y p e s \s * = \s * 1 \s * \) \s * ; ) \s * / i)
0 commit comments