2019-06-27 10:03:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Registers controllers in the blocks REST API namespace.
|
|
|
|
*
|
|
|
|
* @package WooCommerce/Blocks
|
|
|
|
*/
|
|
|
|
|
2019-06-27 10:28:52 +00:00
|
|
|
namespace Automattic\WooCommerce\Blocks;
|
2019-06-27 10:03:21 +00:00
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RestApi class.
|
|
|
|
*/
|
|
|
|
class RestApi {
|
|
|
|
|
|
|
|
/**
|
2019-06-27 10:28:52 +00:00
|
|
|
* Initialize class features.
|
2019-06-27 10:03:21 +00:00
|
|
|
*/
|
2019-06-27 10:28:52 +00:00
|
|
|
public static function init() {
|
|
|
|
add_action( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ), 10 );
|
|
|
|
}
|
2019-06-27 10:03:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register REST API routes.
|
|
|
|
*/
|
2019-06-27 10:28:52 +00:00
|
|
|
public static function register_rest_routes() {
|
|
|
|
$controllers = self::get_controllers();
|
2019-06-27 10:03:21 +00:00
|
|
|
|
2019-06-27 10:28:52 +00:00
|
|
|
foreach ( $controllers as $name => $class ) {
|
|
|
|
$instance = new $class();
|
|
|
|
$instance->register_routes();
|
2019-06-27 10:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of controller classes for this REST API namespace.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected static function get_controllers() {
|
|
|
|
return [
|
|
|
|
'product-attributes' => __NAMESPACE__ . '\RestApi\Controllers\ProductAttributes',
|
|
|
|
'product-attribute-terms' => __NAMESPACE__ . '\RestApi\Controllers\ProductAttributeTerms',
|
|
|
|
'product-categories' => __NAMESPACE__ . '\RestApi\Controllers\ProductCategories',
|
|
|
|
'products' => __NAMESPACE__ . '\RestApi\Controllers\Products',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|