@@ -210,11 +210,11 @@ function static_site_importer_rest_import_figma_file( WP_REST_Request $request )
210210 * @return array<string,mixed>|WP_Error
211211 */
212212function static_site_importer_rest_create_playground_open ( array $ artifact , array $ input , string $ source = 'upload ' ) {
213- $ package = static_site_importer_playground_package ();
213+ $ package = static_site_importer_playground_package ();
214214 if ( is_wp_error ( $ package ) ) {
215215 return $ package ;
216216 }
217- $ blueprint = static_site_importer_playground_import_blueprint ( $ input , array ( 'package ' => $ package ) );
217+ $ blueprint = static_site_importer_playground_import_blueprint ( $ input , array ( 'package ' => $ package ) );
218218 if ( is_wp_error ( $ blueprint ) ) {
219219 return $ blueprint ;
220220 }
@@ -316,19 +316,20 @@ function static_site_importer_playground_import_steps( array $input, array $opti
316316
317317 if ( $ install ) {
318318 $ package_path = '/tmp/static-site-importer- ' . substr ( $ package ['sha256 ' ], 0 , 16 ) . '.zip ' ;
319- $ steps [] = array (
319+ $ steps [] = array (
320320 'step ' => 'writeFile ' ,
321321 'path ' => $ package_path ,
322322 'data ' => array (
323323 'resource ' => 'url ' ,
324324 'url ' => $ package ['url ' ],
325325 ),
326326 );
327- $ steps [] = array (
327+ $ steps [] = array (
328328 'step ' => 'runPHP ' ,
329+ // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- Produces immutable PHP string literals for the Playground blueprint.
329330 'code ' => '<?php if ( ! hash_equals( ' . var_export ( $ package ['sha256 ' ], true ) . ', hash_file( "sha256", ' . var_export ( $ package_path , true ) . ' ) ) ) { throw new RuntimeException( "Static Site Importer package integrity verification failed." ); } ?> ' ,
330331 );
331- $ steps [] = array (
332+ $ steps [] = array (
332333 'step ' => 'installPlugin ' ,
333334 'pluginData ' => array (
334335 'resource ' => 'vfs ' ,
@@ -415,16 +416,18 @@ function static_site_importer_playground_package( array $options = array() ) {
415416 return new WP_Error ( 'static_site_importer_playground_package_missing ' , __ ( 'A pinned, integrity-verified Static Site Importer package is required for Playground previews. ' , 'static-site-importer ' ), array ( 'status ' => 503 ) );
416417 }
417418
418- $ url = isset ( $ package ['url ' ] ) ? (string ) $ package ['url ' ] : '' ;
419- $ version = isset ( $ package ['version ' ] ) ? (string ) $ package ['version ' ] : '' ;
420- $ sha256 = strtolower ( preg_replace ( '/^sha256:/i ' , '' , (string ) ( $ package ['sha256 ' ] ?? $ package ['digest ' ] ?? '' ) ) );
419+ $ url = isset ( $ package ['url ' ] ) ? (string ) $ package ['url ' ] : '' ;
420+ $ version = isset ( $ package ['version ' ] ) ? (string ) $ package ['version ' ] : '' ;
421+ $ sha256 = strtolower ( preg_replace ( '/^sha256:/i ' , '' , (string ) ( $ package ['sha256 ' ] ?? $ package ['digest ' ] ?? '' ) ) );
421422 $ is_development = ! empty ( $ package ['development ' ] );
422423 if ( '' === $ url || '' === $ version || ! preg_match ( '/^[a-f0-9]{64}$/ ' , $ sha256 ) || ! filter_var ( $ url , FILTER_VALIDATE_URL ) ) {
423424 return new WP_Error ( 'static_site_importer_playground_package_invalid ' , __ ( 'The Static Site Importer Playground package must provide a URL, version, and SHA-256 digest. ' , 'static-site-importer ' ), array ( 'status ' => 500 ) );
424425 }
425426
426427 $ release_asset = 'https://github.com/Automattic/static-site-importer/releases/download/ ' . rawurlencode ( $ version ) . '/static-site-importer.zip ' ;
427- $ content_addressed = false !== strpos ( strtolower ( (string ) parse_url ( $ url , PHP_URL_PATH ) ), $ sha256 );
428+ // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- The standalone smoke harness does not load WordPress.
429+ $ url_path = function_exists ( 'wp_parse_url ' ) ? wp_parse_url ( $ url , PHP_URL_PATH ) : parse_url ( $ url , PHP_URL_PATH );
430+ $ content_addressed = false !== strpos ( strtolower ( (string ) $ url_path ), $ sha256 );
428431 if ( ! $ is_development && $ url !== $ release_asset && ! $ content_addressed ) {
429432 return new WP_Error ( 'static_site_importer_playground_package_mutable ' , __ ( 'Static Site Importer Playground previews require a version-pinned release asset or content-addressed package URL. ' , 'static-site-importer ' ), array ( 'status ' => 500 ) );
430433 }
@@ -780,10 +783,10 @@ function static_site_importer_build_playground_preview( array $artifact, array $
780783 */
781784function static_site_importer_rest_apply_to_current_site ( array $ source , array $ input ) {
782785 // Current-site materialization is always inert even when a request carries preview options.
783- $ input ['client_script_policy ' ] = 'inert ' ;
784- $ input ['client_script_isolated ' ] = false ;
786+ $ input ['client_script_policy ' ] = 'inert ' ;
787+ $ input ['client_script_isolated ' ] = false ;
785788 $ input ['client_script_provenance ' ] = array ();
786- $ decorate_current_site_preview = static function ( $ result ) {
789+ $ decorate_current_site_preview = static function ( $ result ) {
787790 if ( ! is_array ( $ result ) ) {
788791 return $ result ;
789792 }
@@ -994,14 +997,14 @@ function static_site_importer_source_runtime( array $source, array $input = arra
994997
995998 $ metadata = isset ( $ source ['metadata ' ] ) && is_array ( $ source ['metadata ' ] ) ? $ source ['metadata ' ] : array ();
996999
997- $ artifact = array_merge (
998- $ metadata ,
999- array (
1000- 'schema ' => 'blocks-engine/php-transformer/site-artifact/v1 ' ,
1001- 'entrypoint ' => $ entrypoint ,
1002- 'files ' => $ files ,
1003- )
1004- );
1000+ $ artifact = array_merge (
1001+ $ metadata ,
1002+ array (
1003+ 'schema ' => 'blocks-engine/php-transformer/site-artifact/v1 ' ,
1004+ 'entrypoint ' => $ entrypoint ,
1005+ 'files ' => $ files ,
1006+ )
1007+ );
10051008 $ source_policy = Static_Site_Importer_Content_Policy::validate_artifact ( $ artifact );
10061009 if ( is_wp_error ( $ source_policy ) ) {
10071010 return $ source_policy ;
@@ -1197,7 +1200,14 @@ function static_site_importer_rest_archive_files( array $archive ) {
11971200 if ( file_exists ( $ tmp ) ) {
11981201 wp_delete_file ( $ tmp );
11991202 }
1200- return new WP_Error ( 'static_site_importer_executable_source_rejected ' , __ ( 'ZIP archives may contain static content only. ' , 'static-site-importer ' ), array ( 'status ' => 400 , 'path ' => $ path ) );
1203+ return new WP_Error (
1204+ 'static_site_importer_executable_source_rejected ' ,
1205+ __ ( 'ZIP archives may contain static content only. ' , 'static-site-importer ' ),
1206+ array (
1207+ 'status ' => 400 ,
1208+ 'path ' => $ path ,
1209+ )
1210+ );
12011211 }
12021212
12031213 $ file_content = $ zip ->getFromIndex ( $ i );
0 commit comments