woocommerce/plugins/woocommerce-blocks/src/RestApi.php

52 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/**
* Registers controllers in the blocks REST API namespace.
*
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks;
defined( 'ABSPATH' ) || exit;
/**
* RestApi class.
*/
class RestApi {
/**
* Initialize class features.
*/
public static function init() {
add_action( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ), 10 );
}
/**
* Register REST API routes.
*/
public static function register_rest_routes() {
$controllers = self::get_controllers();
foreach ( $controllers as $name => $class ) {
$instance = new $class();
$instance->register_routes();
}
}
/**
* 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',
Introduce a new Products by Tag(s) block (https://github.com/woocommerce/woocommerce-blocks/pull/554) * Introduced WGPB_Extend_Core class to modify shortcodes and API requests of core * Require the new class * WC_REST_Blocks_Products_Controller_V2 to override the wc-blocks API to support new tags properties * Register new products by tag block type * Modify utils to support tags and tag_operators * Add ProductTagControl to handle tag searching * Add the actual products by tag block * Set limitTags to 100 * Create Package class and use in main plugin file * Move and refactor library class - split asset methods into new Assets class. * Add jetpack autoloader dependency * fix tests * Update from master * AbstractBlock class for general block registration * remove test autoloader so tests do not break * Create AbstractProductGrid * FeaturedProduct * HandpickedProducts * ProductBestSellers * ProductCategory * ProductNew * ProductOnSale * ProductTopRated * ProductsByAttribute * Remove old base and render functions * Allow non-dynamic blocks and register category block * Fix products-by-attribute due to wrong naming * Remove no dev * test phpunit dir * Update testing framework * Update with new abstract classes and build in API * Undo edit to attribute block * Move edit mode * No need to support shortcodes * correct linting errors * Update tests/bootstrap.php Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update code comment to make more sense. * Correct test package * docblock * Fix cancel button class * Fix classname schema * Set loading state so spinner is shown * Add placeholder element when no tags are selected * No tags placeholder * Update rest endpoints
2019-07-09 13:42:22 +00:00
'product-tags' => __NAMESPACE__ . '\RestApi\Controllers\ProductTags',
'products' => __NAMESPACE__ . '\RestApi\Controllers\Products',
'variations' => __NAMESPACE__ . '\RestApi\Controllers\Variations',
];
}
}