| 1 |
<?php |
| 2 |
/** |
| 3 |
* The contract defining required methods for a REST route. |
| 4 |
* |
| 5 |
* @since 0.1.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace SolidWP\Performance\API; |
| 11 |
|
| 12 |
use WP_Error; |
| 13 |
use WP_REST_Request; |
| 14 |
use WP_REST_Response; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* The contract defining required methods for a REST route. |
| 22 |
* |
| 23 |
* @since 0.1.0 |
| 24 |
* |
| 25 |
* @package SolidWP\Performance |
| 26 |
*/ |
| 27 |
interface Route { |
| 28 |
/** |
| 29 |
* Get the path pattern of the REST API endpoint (e.g. '/author/(?P<id>\d+)'). |
| 30 |
* |
| 31 |
* @since 0.1.0 |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
public function get_path(): string; |
| 36 |
|
| 37 |
/** |
| 38 |
* Gets the HTTP methods that the REST API endpoint responds to. |
| 39 |
* |
| 40 |
* @since 0.1.0 |
| 41 |
* |
| 42 |
* @return mixed |
| 43 |
*/ |
| 44 |
public function get_methods(); |
| 45 |
|
| 46 |
/** |
| 47 |
* The action performed by the REST API endpoint to send a response. |
| 48 |
* |
| 49 |
* @since 0.1.0 |
| 50 |
* |
| 51 |
* @param WP_REST_Request $request The current request for the route. |
| 52 |
* |
| 53 |
* @return WP_REST_Response|WP_Error |
| 54 |
*/ |
| 55 |
public function callback( WP_REST_Request $request ); |
| 56 |
|
| 57 |
/** |
| 58 |
* Gets the expected arguments for the REST API endpoint. |
| 59 |
* |
| 60 |
* Having an index of the HTTP method (e.g. POST, GET) will apply the args directly to |
| 61 |
* that method if the route is more than one method. |
| 62 |
* |
| 63 |
* @since 0.1.0 |
| 64 |
* |
| 65 |
* @return array<string, array<string, mixed[]>> |
| 66 |
*/ |
| 67 |
public function get_arguments(): array; |
| 68 |
|
| 69 |
/** |
| 70 |
* Ensures user can make a request to the REST API endpoint. |
| 71 |
* |
| 72 |
* @since 0.1.0 |
| 73 |
* |
| 74 |
* @return bool |
| 75 |
*/ |
| 76 |
public function permission_callback(): bool; |
| 77 |
|
| 78 |
/** |
| 79 |
* The callback used to output schema for the route. |
| 80 |
* |
| 81 |
* @since 0.1.0 |
| 82 |
* |
| 83 |
* @return array |
| 84 |
*/ |
| 85 |
public function schema_callback(): array; |
| 86 |
} |
| 87 |
|