Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RestApi | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| register_routes | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Module\Performance\RestApi; |
| 3 | |
| 4 | /** |
| 5 | * Instantiate controllers and register routes. |
| 6 | */ |
| 7 | final class RestApi { |
| 8 | |
| 9 | /** |
| 10 | * List of custom REST API controllers |
| 11 | * |
| 12 | * @var array |
| 13 | */ |
| 14 | protected $controllers = array( |
| 15 | 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\Skip404Controller', |
| 16 | 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\LinkPrefetchController', |
| 17 | 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\JetpackController', |
| 18 | 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\CacheController', |
| 19 | ); |
| 20 | |
| 21 | /** |
| 22 | * Setup the custom REST API |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Register the custom REST API routes |
| 30 | */ |
| 31 | public function register_routes() { |
| 32 | foreach ( $this->controllers as $controller ) { |
| 33 | /** |
| 34 | * Get an instance of the WP_REST_Controller. |
| 35 | * |
| 36 | * @var $instance WP_REST_Controller |
| 37 | */ |
| 38 | $instance = new $controller(); |
| 39 | $instance->register_routes(); |
| 40 | } |
| 41 | } |
| 42 | } |