Skip to content

Commit f588cf5

Browse files
committed
Move function to top so it shows more clearly in the diff.
1 parent 3050cd1 commit f588cf5

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

tools/gutenberg/copy.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,42 @@ const COPY_CONFIG = {
113113
],
114114
};
115115

116+
/**
117+
* Given a path to a PHP file which returns a single value, converts that
118+
* value into a native JavaScript value (limited by JSON serialization).
119+
*
120+
* @throws Error when PHP source file unable to be read, or PHP is unavailable.
121+
*
122+
* @param {string} phpFilepath Absolute path of PHP file returning a single value.
123+
* @return {Object|Array} JavaScript representation of value from input file.
124+
*/
125+
function readReturnedValueFromPHPFile( phpFilepath ) {
126+
const results = child_process.spawnSync(
127+
'php',
128+
[ '-r', '$path = file_get_contents( "php://stdin" ); if ( ! is_file( $path ) ) { die( 1 ); } try { $data = require $path; } catch ( \\Throwable $e ) { die( 2 ); } $json = json_encode( $data ); if ( ! is_string( $json ) ) { die( 3 ); } echo $json;' ],
129+
{
130+
encoding: 'utf8',
131+
input: phpFilepath,
132+
}
133+
);
134+
135+
switch ( results.status ) {
136+
case 0:
137+
return JSON.parse( results.stdout );
138+
139+
case 1:
140+
throw new Error( `Could not read PHP source file: '${ phpFilepath }'` );
141+
142+
case 2:
143+
throw new Error( `PHP source file did not return value when imported: '${ phpFilepath }'` );
144+
145+
case 3:
146+
throw new Error( `Could not serialize PHP source value into JSON: '${ phpFilepath }'` );
147+
}
148+
149+
throw new Error( `Unknown error while reading PHP source file: '${ phpFilepath }'` );
150+
}
151+
116152
/**
117153
* Check if a block is experimental by reading its block.json.
118154
*
@@ -647,42 +683,6 @@ function generateBlocksJson() {
647683
);
648684
}
649685

650-
/**
651-
* Given a path to a PHP file which returns a single value, converts that
652-
* value into a native JavaScript value (limited by JSON serialization).
653-
*
654-
* @throws Error when PHP source file unable to be read, or PHP is unavailable.
655-
*
656-
* @param {string} phpFilepath Absolute path of PHP file returning a single value.
657-
* @return {Object|Array} JavaScript representation of value from input file.
658-
*/
659-
function readReturnedValueFromPHPFile( phpFilepath ) {
660-
const results = child_process.spawnSync(
661-
'php',
662-
[ '-r', '$path = file_get_contents( "php://stdin" ); if ( ! is_file( $path ) ) { die( 1 ); } try { $data = require $path; } catch ( \\Throwable $e ) { die( 2 ); } $json = json_encode( $data ); if ( ! is_string( $json ) ) { die( 3 ); } echo $json;' ],
663-
{
664-
encoding: 'utf8',
665-
input: phpFilepath,
666-
}
667-
);
668-
669-
switch ( results.status ) {
670-
case 0:
671-
return JSON.parse( results.stdout );
672-
673-
case 1:
674-
throw new Error( `Could not read PHP source file: '${ phpFilepath }'` );
675-
676-
case 2:
677-
throw new Error( `PHP source file did not return value when imported: '${ phpFilepath }'` );
678-
679-
case 3:
680-
throw new Error( `Could not serialize PHP source value into JSON: '${ phpFilepath }'` );
681-
}
682-
683-
throw new Error( `Unknown error while reading PHP source file: '${ phpFilepath }'` );
684-
}
685-
686686
/**
687687
* Main execution function.
688688
*/

0 commit comments

Comments
 (0)