Update all other namespaces

This commit is contained in:
Mike Jolley 2019-05-30 18:23:39 +01:00
parent d630418f26
commit 13b18a4211
8 changed files with 221 additions and 127 deletions

View File

@ -40,7 +40,7 @@ class RestApi {
*/
public function register_rest_routes() {
foreach ( $this->get_rest_namespaces() as $namespace => $namespace_class ) {
$controllers = $namespace_class::instance()->get_controllers();
$controllers = $namespace_class::get_controllers();
foreach ( $controllers as $controller_name => $controller_class ) {
$this->endpoints[ $namespace ][ $controller_name ] = new $controller_class();
@ -52,132 +52,36 @@ class RestApi {
/**
* Get API namespaces - new namespaces should be registered here.
*
* @return array
* @return array List of Namespaces and Main controller classes.
*/
protected function get_rest_namespaces() {
return [
//'wc/v1',
//'wc/v2',
'wc/v3' => '\WooCommerce\RestApi\Version4\Main',
//'wc-blocks/v1',
'wc/v1' => 'WC_REST_Controllers_V1',
'wc/v2' => 'WC_REST_Controllers_V2',
'wc/v3' => 'WC_REST_Controllers_V3',
'wc/v4' => '\WooCommerce\RestApi\Version4\Controllers',
'wc-blocks/v1' => 'WC_REST_Blocks_Controllers',
];
}
/**
* Get API controllers - new controllers/endpoints should be registered here.
* Get data from a WooCommerce API endpoint.
*
* @param string $namespace Namespace to get controllers for.
* @return array
* @param string $endpoint Endpoint.
* @param array $params Params to passwith request.
* @return array|WP_Error
*/
protected function get_rest_controllers( $namespace ) {
switch ( $namespace ) {
case 'wc/v1':
return [
'WC_REST_Coupons_V1_Controller',
'WC_REST_Customer_Downloads_V1_Controller',
'WC_REST_Customers_V1_Controller',
'WC_REST_Order_Notes_V1_Controller',
'WC_REST_Order_Refunds_V1_Controller',
'WC_REST_Orders_V1_Controller',
'WC_REST_Product_Attribute_Terms_V1_Controller',
'WC_REST_Product_Attributes_V1_Controller',
'WC_REST_Product_Categories_V1_Controller',
'WC_REST_Product_Reviews_V1_Controller',
'WC_REST_Product_Shipping_Classes_V1_Controller',
'WC_REST_Product_Tags_V1_Controller',
'WC_REST_Products_V1_Controller',
'WC_REST_Report_Sales_V1_Controller',
'WC_REST_Report_Top_Sellers_V1_Controller',
'WC_REST_Reports_V1_Controller',
'WC_REST_Tax_Classes_V1_Controller',
'WC_REST_Taxes_V1_Controller',
'WC_REST_Webhook_Deliveries_V1_Controller',
'WC_REST_Webhooks_V1_Controller',
];
case 'wc/v2':
return [
'WC_REST_Coupons_V2_Controller',
'WC_REST_Customer_Downloads_V2_Controller',
'WC_REST_Customers_V2_Controller',
'WC_REST_Network_Orders_V2_Controller',
'WC_REST_Order_Notes_V2_Controller',
'WC_REST_Order_Refunds_V2_Controller',
'WC_REST_Orders_V2_Controller',
'WC_REST_Product_Attribute_Terms_V2_Controller',
'WC_REST_Product_Attributes_V2_Controller',
'WC_REST_Product_Categories_V2_Controller',
'WC_REST_Product_Reviews_V2_Controller',
'WC_REST_Product_Shipping_Classes_V2_Controller',
'WC_REST_Product_Tags_V2_Controller',
'WC_REST_Products_V2_Controller',
'WC_REST_Product_Variations_V2_Controller',
'WC_REST_Report_Sales_V2_Controller',
'WC_REST_Report_Top_Sellers_V2_Controller',
'WC_REST_Reports_V2_Controller',
'WC_REST_Settings_V2_Controller',
'WC_REST_Setting_Options_V2_Controller',
'WC_REST_Shipping_Zones_V2_Controller',
'WC_REST_Shipping_Zone_Locations_V2_Controller',
'WC_REST_Shipping_Zone_Methods_V2_Controller',
'WC_REST_Tax_Classes_V2_Controller',
'WC_REST_Taxes_V2_Controller',
'WC_REST_Webhook_Deliveries_V2_Controller',
'WC_REST_Webhooks_V2_Controller',
'WC_REST_System_Status_V2_Controller',
'WC_REST_System_Status_Tools_V2_Controller',
'WC_REST_Shipping_Methods_V2_Controller',
'WC_REST_Payment_Gateways_V2_Controller',
];
case 'wc/v3':
return [
'WC_REST_Coupons_Controller',
'WC_REST_Customer_Downloads_Controller',
'WC_REST_Customers_Controller',
'WC_REST_Network_Orders_Controller',
'WC_REST_Order_Notes_Controller',
'WC_REST_Order_Refunds_Controller',
'WC_REST_Orders_Controller',
'WC_REST_Product_Attribute_Terms_Controller',
'WC_REST_Product_Attributes_Controller',
'WC_REST_Product_Categories_Controller',
'WC_REST_Product_Reviews_Controller',
'WC_REST_Product_Shipping_Classes_Controller',
'WC_REST_Product_Tags_Controller',
'WC_REST_Products_Controller',
'WC_REST_Product_Variations_Controller',
'WC_REST_Report_Sales_Controller',
'WC_REST_Report_Top_Sellers_Controller',
'WC_REST_Report_Orders_Totals_Controller',
'WC_REST_Report_Products_Totals_Controller',
'WC_REST_Report_Customers_Totals_Controller',
'WC_REST_Report_Coupons_Totals_Controller',
'WC_REST_Report_Reviews_Totals_Controller',
'WC_REST_Reports_Controller',
'WC_REST_Settings_Controller',
'WC_REST_Setting_Options_Controller',
'WC_REST_Shipping_Zones_Controller',
'WC_REST_Shipping_Zone_Locations_Controller',
'WC_REST_Shipping_Zone_Methods_Controller',
'WC_REST_Tax_Classes_Controller',
'WC_REST_Taxes_Controller',
'WC_REST_Webhooks_Controller',
'WC_REST_System_Status_Controller',
'WC_REST_System_Status_Tools_Controller',
'WC_REST_Shipping_Methods_Controller',
'WC_REST_Payment_Gateways_Controller',
'WC_REST_Data_Controller',
'WC_REST_Data_Continents_Controller',
'WC_REST_Data_Countries_Controller',
'WC_REST_Data_Currencies_Controller',
];
case 'wc-blocks/v1':
return [
'WC_REST_Blocks_Product_Attributes_Controller',
'WC_REST_Blocks_Product_Attribute_Terms_Controller',
'WC_REST_Blocks_Product_Categories_Controller',
'WC_REST_Blocks_Products_Controller',
];
public function get_endpoint_data( $endpoint, $params = array() ) {
$request = new \WP_REST_Request( 'GET', $endpoint );
if ( $params ) {
$request->set_query_params( $params );
}
return [];
$response = \rest_do_request( $request );
$server = \rest_get_server();
$json = wp_json_encode( $server->response_to_data( $response, false ) );
return json_decode( $json, true );
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* Returns controllers in this REST API namespace.
*
* @package WooCommerce/RestApi
*/
defined( 'ABSPATH' ) || exit;
/**
* Controllers class.
*/
class WC_REST_Blocks_Controllers {
/**
* Return a list of controller classes for this REST API namespace.
*
* @return array
*/
public static function get_controllers() {
return [
'product-attributes' => 'WC_REST_Blocks_Product_Attributes_Controller',
'product-attribute-terms' => 'WC_REST_Blocks_Product_Attribute_Terms_Controller',
'product-categories' => 'WC_REST_Blocks_Product_Categories_Controller',
'products' => 'WC_REST_Blocks_Products_Controller',
];
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Returns controllers in this REST API namespace.
*
* @package WooCommerce/RestApi
*/
defined( 'ABSPATH' ) || exit;
/**
* Controllers class.
*/
class WC_REST_Controllers_V1 {
/**
* Return a list of controller classes for this REST API namespace.
*
* @return array
*/
public static function get_controllers() {
return [
'coupons' => 'WC_REST_Coupons_V1_Controller',
'customer-downloads' => 'WC_REST_Customer_Downloads_V1_Controller',
'customers' => 'WC_REST_Customers_V1_Controller',
'order-notes' => 'WC_REST_Order_Notes_V1_Controller',
'order-refunds' => 'WC_REST_Order_Refunds_V1_Controller',
'orders' => 'WC_REST_Orders_V1_Controller',
'product-attribute-terms' => 'WC_REST_Product_Attribute_Terms_V1_Controller',
'product-attributes' => 'WC_REST_Product_Attributes_V1_Controller',
'product-categories' => 'WC_REST_Product_Categories_V1_Controller',
'product-reviews' => 'WC_REST_Product_Reviews_V1_Controller',
'product-shipping-classes' => 'WC_REST_Product_Shipping_Classes_V1_Controller',
'product-tags' => 'WC_REST_Product_Tags_V1_Controller',
'products' => 'WC_REST_Products_V1_Controller',
'reports-sales' => 'WC_REST_Report_Sales_V1_Controller',
'reports-top-sellers' => 'WC_REST_Report_Top_Sellers_V1_Controller',
'reports' => 'WC_REST_Reports_V1_Controller',
'tax-classes' => 'WC_REST_Tax_Classes_V1_Controller',
'taxes' => 'WC_REST_Taxes_V1_Controller',
'webhooks' => 'WC_REST_Webhooks_V1_Controller',
'webhook-deliveries' => 'WC_REST_Webhook_Deliveries_V1_Controller',
];
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Returns controllers in this REST API namespace.
*
* @package WooCommerce/RestApi
*/
defined( 'ABSPATH' ) || exit;
/**
* Controllers class.
*/
class WC_REST_Controllers_V2 {
/**
* Return a list of controller classes for this REST API namespace.
*
* @return array
*/
public static function get_controllers() {
return [
'coupons' => 'WC_REST_Coupons_V2_Controller',
'customer-downloads' => 'WC_REST_Customer_Downloads_V2_Controller',
'customers' => 'WC_REST_Customers_V2_Controller',
'network-orders' => 'WC_REST_Network_Orders_V2_Controller',
'order-notes' => 'WC_REST_Order_Notes_V2_Controller',
'order-refunds' => 'WC_REST_Order_Refunds_V2_Controller',
'orders' => 'WC_REST_Orders_V2_Controller',
'product-attribute-terms' => 'WC_REST_Product_Attribute_Terms_V2_Controller',
'product-attributes' => 'WC_REST_Product_Attributes_V2_Controller',
'product-categories' => 'WC_REST_Product_Categories_V2_Controller',
'product-reviews' => 'WC_REST_Product_Reviews_V2_Controller',
'product-shipping-classes' => 'WC_REST_Product_Shipping_Classes_V2_Controller',
'product-tags' => 'WC_REST_Product_Tags_V2_Controller',
'products' => 'WC_REST_Products_V2_Controller',
'product-variations' => 'WC_REST_Product_Variations_V2_Controller',
'reports-sales' => 'WC_REST_Report_Sales_V2_Controller',
'reports-top-sellers' => 'WC_REST_Report_Top_Sellers_V2_Controller',
'reports' => 'WC_REST_Reports_V2_Controller',
'settings' => 'WC_REST_Settings_V2_Controller',
'settings-options' => 'WC_REST_Setting_Options_V2_Controller',
'shipping-zones' => 'WC_REST_Shipping_Zones_V2_Controller',
'shipping-zone-locations' => 'WC_REST_Shipping_Zone_Locations_V2_Controller',
'shipping-zone-methods' => 'WC_REST_Shipping_Zone_Methods_V2_Controller',
'tax-classes' => 'WC_REST_Tax_Classes_V2_Controller',
'taxes' => 'WC_REST_Taxes_V2_Controller',
'webhooks' => 'WC_REST_Webhooks_V2_Controller',
'webhook-deliveries' => 'WC_REST_Webhook_Deliveries_V2_Controller',
'system-status' => 'WC_REST_System_Status_V2_Controller',
'system-status-tools' => 'WC_REST_System_Status_Tools_V2_Controller',
'shipping-methods' => 'WC_REST_Shipping_Methods_V2_Controller',
'payment-gateways' => 'WC_REST_Payment_Gateways_V2_Controller',
];
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Returns controllers in this REST API namespace.
*
* @package WooCommerce/RestApi
*/
defined( 'ABSPATH' ) || exit;
/**
* Controllers class.
*/
class WC_REST_Controllers_V3 {
/**
* Return a list of controller classes for this REST API namespace.
*
* @return array
*/
public static function get_controllers() {
return [
'coupons' => 'WC_REST_Coupons_Controller',
'customer-downloads' => 'WC_REST_Customer_Downloads_Controller',
'customers' => 'WC_REST_Customers_Controller',
'network-orders' => 'WC_REST_Network_Orders_Controller',
'order-notes' => 'WC_REST_Order_Notes_Controller',
'order-refunds' => 'WC_REST_Order_Refunds_Controller',
'orders' => 'WC_REST_Orders_Controller',
'product-attribute-terms' => 'WC_REST_Product_Attribute_Terms_Controller',
'product-attributes' => 'WC_REST_Product_Attributes_Controller',
'product-categories' => 'WC_REST_Product_Categories_Controller',
'product-reviews' => 'WC_REST_Product_Reviews_Controller',
'product-shipping-classes' => 'WC_REST_Product_Shipping_Classes_Controller',
'product-tags' => 'WC_REST_Product_Tags_Controller',
'products' => 'WC_REST_Products_Controller',
'product-variations' => 'WC_REST_Product_Variations_Controller',
'reports-sales' => 'WC_REST_Report_Sales_Controller',
'reports-top-sellers' => 'WC_REST_Report_Top_Sellers_Controller',
'reports-orders-totals' => 'WC_REST_Report_Orders_Totals_Controller',
'reports-products-totals' => 'WC_REST_Report_Products_Totals_Controller',
'reports-customers-totals' => 'WC_REST_Report_Customers_Totals_Controller',
'reports-coupons-totals' => 'WC_REST_Report_Coupons_Totals_Controller',
'reports-reviews-totals' => 'WC_REST_Report_Reviews_Totals_Controller',
'reports' => 'WC_REST_Reports_Controller',
'settings' => 'WC_REST_Settings_Controller',
'settings-options' => 'WC_REST_Setting_Options_Controller',
'shipping-zones' => 'WC_REST_Shipping_Zones_Controller',
'shipping-zone-locations' => 'WC_REST_Shipping_Zone_Locations_Controller',
'shipping-zone-methods' => 'WC_REST_Shipping_Zone_Methods_Controller',
'tax-classes' => 'WC_REST_Tax_Classes_Controller',
'taxes' => 'WC_REST_Taxes_Controller',
'webhooks' => 'WC_REST_Webhooks_Controller',
'system-status' => 'WC_REST_System_Status_Controller',
'system-status-tools' => 'WC_REST_System_Status_Tools_Controller',
'shipping-methods' => 'WC_REST_Shipping_Methods_Controller',
'payment-gateways' => 'WC_REST_Payment_Gateways_Controller',
'data' => 'WC_REST_Data_Controller',
'data-continents' => 'WC_REST_Data_Continents_Controller',
'data-countries' => 'WC_REST_Data_Countries_Controller',
'data-currencies' => 'WC_REST_Data_Currencies_Controller',
];
}
}

View File

@ -9,20 +9,16 @@ namespace WooCommerce\RestApi\Version4;
defined( 'ABSPATH' ) || exit;
use WooCommerce\Utilities\SingletonTrait;
/**
* Main V4 namespace class.
* Controllers class.
*/
class Main {
use SingletonTrait;
class Controllers {
/**
* Return a list of controller classes for this REST API namespace.
*
* @return array
*/
public function get_controllers() {
public static function get_controllers() {
$controllers = [
'coupons' => __NAMESPACE__ . '\Controllers\Coupons',
'customer-downloads' => __NAMESPACE__ . '\Controllers\CustomerDownloads',

View File

@ -6,12 +6,16 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'WC_REST_Blocks_Controllers' => $baseDir . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-controllers.php',
'WC_REST_Blocks_Product_Attribute_Terms_Controller' => $baseDir . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-product-attribute-terms-controller.php',
'WC_REST_Blocks_Product_Attributes_Controller' => $baseDir . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-product-attributes-controller.php',
'WC_REST_Blocks_Product_Categories_Controller' => $baseDir . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-product-categories-controller.php',
'WC_REST_Blocks_Products_Controller' => $baseDir . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-products-controller.php',
'WC_REST_CRUD_Controller' => $baseDir . '/src/RestApi/Version3/class-wc-rest-crud-controller.php',
'WC_REST_Controller' => $baseDir . '/src/RestApi/Version3/class-wc-rest-controller.php',
'WC_REST_Controllers_V1' => $baseDir . '/src/RestApi/Version1/class-wc-rest-controllers-v1.php',
'WC_REST_Controllers_V2' => $baseDir . '/src/RestApi/Version2/class-wc-rest-controllers-v2.php',
'WC_REST_Controllers_V3' => $baseDir . '/src/RestApi/Version3/class-wc-rest-controllers-v3.php',
'WC_REST_Coupons_Controller' => $baseDir . '/src/RestApi/Version3/class-wc-rest-coupons-controller.php',
'WC_REST_Coupons_V1_Controller' => $baseDir . '/src/RestApi/Version1/class-wc-rest-coupons-v1-controller.php',
'WC_REST_Coupons_V2_Controller' => $baseDir . '/src/RestApi/Version2/class-wc-rest-coupons-v2-controller.php',
@ -106,6 +110,7 @@ return array(
'WC_REST_Webhooks_V1_Controller' => $baseDir . '/src/RestApi/Version1/class-wc-rest-webhooks-v1-controller.php',
'WC_REST_Webhooks_V2_Controller' => $baseDir . '/src/RestApi/Version2/class-wc-rest-webhooks-v2-controller.php',
'WooCommerce\\RestApi' => $baseDir . '/src/RestApi.php',
'WooCommerce\\RestApi\\Version4\\Controllers' => $baseDir . '/src/RestApi/Version4/Controllers.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\AbstractController' => $baseDir . '/src/RestApi/Version4/Controllers/AbstractController.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\AbstractObjectsController' => $baseDir . '/src/RestApi/Version4/Controllers/AbstractObjectsController.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\AbstractPostsController' => $baseDir . '/src/RestApi/Version4/Controllers/AbstractPostsController.php',
@ -167,6 +172,5 @@ return array(
'WooCommerce\\RestApi\\Version4\\Controllers\\TaxClasses' => $baseDir . '/src/RestApi/Version4/Controllers/TaxClasses.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\Taxes' => $baseDir . '/src/RestApi/Version4/Controllers/Taxes.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\Webhooks' => $baseDir . '/src/RestApi/Version4/Controllers/Webhooks.php',
'WooCommerce\\RestApi\\Version4\\Main' => $baseDir . '/src/RestApi/Version4/Main.php',
'WooCommerce\\Utilities\\SingletonTrait' => $baseDir . '/src/Utilities/SingletonTrait.php',
);

View File

@ -7,12 +7,16 @@ namespace Composer\Autoload;
class ComposerStaticInitf71e7bc9895f702f48d84a180f514421
{
public static $classMap = array (
'WC_REST_Blocks_Controllers' => __DIR__ . '/../..' . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-controllers.php',
'WC_REST_Blocks_Product_Attribute_Terms_Controller' => __DIR__ . '/../..' . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-product-attribute-terms-controller.php',
'WC_REST_Blocks_Product_Attributes_Controller' => __DIR__ . '/../..' . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-product-attributes-controller.php',
'WC_REST_Blocks_Product_Categories_Controller' => __DIR__ . '/../..' . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-product-categories-controller.php',
'WC_REST_Blocks_Products_Controller' => __DIR__ . '/../..' . '/src/RestApi/Blocks/Version1/class-wc-rest-blocks-products-controller.php',
'WC_REST_CRUD_Controller' => __DIR__ . '/../..' . '/src/RestApi/Version3/class-wc-rest-crud-controller.php',
'WC_REST_Controller' => __DIR__ . '/../..' . '/src/RestApi/Version3/class-wc-rest-controller.php',
'WC_REST_Controllers_V1' => __DIR__ . '/../..' . '/src/RestApi/Version1/class-wc-rest-controllers-v1.php',
'WC_REST_Controllers_V2' => __DIR__ . '/../..' . '/src/RestApi/Version2/class-wc-rest-controllers-v2.php',
'WC_REST_Controllers_V3' => __DIR__ . '/../..' . '/src/RestApi/Version3/class-wc-rest-controllers-v3.php',
'WC_REST_Coupons_Controller' => __DIR__ . '/../..' . '/src/RestApi/Version3/class-wc-rest-coupons-controller.php',
'WC_REST_Coupons_V1_Controller' => __DIR__ . '/../..' . '/src/RestApi/Version1/class-wc-rest-coupons-v1-controller.php',
'WC_REST_Coupons_V2_Controller' => __DIR__ . '/../..' . '/src/RestApi/Version2/class-wc-rest-coupons-v2-controller.php',
@ -107,6 +111,7 @@ class ComposerStaticInitf71e7bc9895f702f48d84a180f514421
'WC_REST_Webhooks_V1_Controller' => __DIR__ . '/../..' . '/src/RestApi/Version1/class-wc-rest-webhooks-v1-controller.php',
'WC_REST_Webhooks_V2_Controller' => __DIR__ . '/../..' . '/src/RestApi/Version2/class-wc-rest-webhooks-v2-controller.php',
'WooCommerce\\RestApi' => __DIR__ . '/../..' . '/src/RestApi.php',
'WooCommerce\\RestApi\\Version4\\Controllers' => __DIR__ . '/../..' . '/src/RestApi/Version4/Controllers.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\AbstractController' => __DIR__ . '/../..' . '/src/RestApi/Version4/Controllers/AbstractController.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\AbstractObjectsController' => __DIR__ . '/../..' . '/src/RestApi/Version4/Controllers/AbstractObjectsController.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\AbstractPostsController' => __DIR__ . '/../..' . '/src/RestApi/Version4/Controllers/AbstractPostsController.php',
@ -168,7 +173,6 @@ class ComposerStaticInitf71e7bc9895f702f48d84a180f514421
'WooCommerce\\RestApi\\Version4\\Controllers\\TaxClasses' => __DIR__ . '/../..' . '/src/RestApi/Version4/Controllers/TaxClasses.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\Taxes' => __DIR__ . '/../..' . '/src/RestApi/Version4/Controllers/Taxes.php',
'WooCommerce\\RestApi\\Version4\\Controllers\\Webhooks' => __DIR__ . '/../..' . '/src/RestApi/Version4/Controllers/Webhooks.php',
'WooCommerce\\RestApi\\Version4\\Main' => __DIR__ . '/../..' . '/src/RestApi/Version4/Main.php',
'WooCommerce\\Utilities\\SingletonTrait' => __DIR__ . '/../..' . '/src/Utilities/SingletonTrait.php',
);