Skip to content

Commit

Permalink
API: Fix #1531
Browse files Browse the repository at this point in the history
This needs to load a local file path and no remote path.
Reverts commit 751b26a
But leaves new exception for troubleshooting purposes, when file_get_contents returns false.
  • Loading branch information
datengraben committed Mar 4, 2024
1 parent b3dde75 commit 308f6a7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/API/BaseRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,26 @@ protected function getSchemaObject(): Schema {
/**
* Returns schema json for current route.
*
* @return array|WP_Error
* @throws RuntimeException On missing schema files.
* @return string
*/
protected function getSchemaJson() {
$schemaArray = wp_remote_get( $this->schemaUrl );
if ( is_array( $schemaArray ) && ! is_wp_error( $schemaArray )) {
protected function getSchemaJson(): string {
$schemaArray = file_get_contents( $this->schemaUrl ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
if ( $schemaArray ) {
return $schemaArray;
} else {
throw new RuntimeException("Could not retrieve schema json from " . $this->schemaUrl );
throw new RuntimeException( 'Could not retrieve schema json from ' . esc_url( $this->schemaUrl ) );
}
}

/**
* Adds schema-fields for output to current route.
*
* @param array $schema
*
* @param array $schema Assoc array of schema json object.
* @return array
*/
public function add_additional_fields_schema( $schema ): array {
$schemaArray = json_decode( $this->getSchemaJson(), true ); // TODO verify that this works and doesn't expects ['body'] from wp_remote_get?
$schemaArray = json_decode( $this->getSchemaJson(), true );

return array_merge( $schema, $schemaArray );
}
Expand Down

0 comments on commit 308f6a7

Please sign in to comment.