Naming improvements
This commit is contained in:
parent
6077ef0fd8
commit
f5768bfd25
35
README.md
35
README.md
|
@ -1 +1,34 @@
|
|||
TODO
|
||||
---
|
||||
title: 'WooCommerce REST API'
|
||||
---
|
||||
|
||||
WooCommerce REST API
|
||||
===
|
||||
|
||||
This repository houses the WooCommerce REST API found in the core WooCommerce plugin.
|
||||
|
||||
It can also be used as a standalone plugin (it still requires WooCommerce!), or can be pulled into other projects and feature plugins that need new API features that are not yet in the core release.
|
||||
|
||||
Once stable, changes in woocommerce-rest-api are brought over to [WooCommerce core](https://github.com/woocommerce/woocommerce) when they are ready for release.
|
||||
|
||||
## Endpoint namespaces
|
||||
|
||||
* Current stable WC REST API version: **wc/v3** - **[Docs](https://woocommerce.github.io/woocommerce-rest-api-docs/)**
|
||||
* WC Blocks REST API version (internal use only): **wc-blocks/v1**
|
||||
* Older versions:
|
||||
* **wc/v1** - **[Docs](https://woocommerce.github.io/woocommerce-rest-api-docs/wp-api-v1.html)**
|
||||
* **wc/v2** - **[Docs](https://woocommerce.github.io/woocommerce-rest-api-docs/wp-api-v2.html)**
|
||||
|
||||
## Contributing
|
||||
|
||||
Please read the [WooCommerce contributor guidelines](https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md) for more information how you can contribute.
|
||||
|
||||
Endpoints are located in the `includes/` directory. Endpoints currently inherit from the stable version of the endpoint. If you need to change the behavior of an endpoint, you can do so in these classes.
|
||||
|
||||
phpunit tests for the API are located in the `tests/unit-tests/` folder and are also merged and shipped with WooCommerce core. You can use the same helpers/framework files that core uses, or introduce new ones.
|
||||
|
||||
Run tests using `phpunit` in the root of this folder. Code coverage reports can be ran with `phpunit --coverage-html /tmp/coverage`.
|
||||
|
||||
## Translation
|
||||
|
||||
For strings located in API endpoints, use `woocommerce` as your text-domain. These endpoints will at some point be merged back into WooCommerce Core.
|
||||
|
|
146
RestApi.php
146
RestApi.php
|
@ -1,146 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Load REST API Namespaces.
|
||||
*
|
||||
* @package WooCommerce/RestAPI/Classes
|
||||
*/
|
||||
|
||||
namespace WC\RestAPI;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class responsible for loading REST API Namespaces.
|
||||
*/
|
||||
class RestApi {
|
||||
|
||||
/**
|
||||
* REST API namespaces.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $namespaces = array();
|
||||
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct() {}
|
||||
|
||||
/**
|
||||
* Get class instance.
|
||||
*
|
||||
* @return object Instance.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( null === static::$instance ) {
|
||||
static::$instance = new static();
|
||||
}
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent cloning.
|
||||
*/
|
||||
private function __clone() {}
|
||||
|
||||
/**
|
||||
* Prevent unserializing.
|
||||
*/
|
||||
private function __wakeup() {}
|
||||
|
||||
/**
|
||||
* Hook into WordPress ready to init the REST API as needed.
|
||||
*/
|
||||
public function init() {
|
||||
spl_autoload_register( array( $this, 'autoload' ) );
|
||||
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a class name and turn it into a file name.
|
||||
*
|
||||
* @param string $class Class name.
|
||||
* @param string $prefix Class prefix.
|
||||
* @return string
|
||||
*/
|
||||
protected function get_file_name_from_class( $class, $prefix = 'class-' ) {
|
||||
return $prefix . str_replace( '_', '-', $class ) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Autoloader.
|
||||
*
|
||||
* @param string $class Classname.
|
||||
*/
|
||||
public function autoload( $class ) {
|
||||
$class = str_replace( '\\', DIRECTORY_SEPARATOR, str_replace( '\\' . __NAMESPACE__ . '\\', '', $class ) );
|
||||
|
||||
// Non-namespaced files.
|
||||
if ( stristr( $class, 'WC_REST_' ) ) {
|
||||
if ( stristr( $class, '_V1_' ) ) {
|
||||
$dir = dirname( __FILE__ ) . '/includes/v1/';
|
||||
} elseif ( stristr( $class, '_V2_' ) ) {
|
||||
$dir = dirname( __FILE__ ) . '/includes/v2/';
|
||||
} elseif ( stristr( $class, 'WC_REST_Blocks' ) ) {
|
||||
$dir = dirname( __FILE__ ) . '/includes/wc-blocks/';
|
||||
} else {
|
||||
$dir = dirname( __FILE__ ) . '/includes/v3/';
|
||||
}
|
||||
|
||||
$file = $this->get_file_name_from_class( $class );
|
||||
|
||||
if ( file_exists( "{$dir}{$file}" ) ) {
|
||||
include "{$dir}{$file}";
|
||||
return;
|
||||
}
|
||||
|
||||
$file = $this->get_file_name_from_class( $class, 'abstract-' );
|
||||
|
||||
if ( file_exists( dirname( __FILE__ ) . "/includes/abstracts/{$file}" ) ) {
|
||||
include dirname( __FILE__ ) . "/includes/abstracts/{$file}";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( file_exists( dirname( __FILE__ ) . "/includes/{$class}.php" ) ) {
|
||||
include dirname( __FILE__ ) . "/includes/{$class}.php";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API namespaces.
|
||||
*/
|
||||
protected function get_namespaces() {
|
||||
return array(
|
||||
'wc/v1' => 'WC_Rest_API_V1',
|
||||
'wc/v2' => 'WC_Rest_API_V2',
|
||||
'wc/v3' => 'WC_Rest_API_V3',
|
||||
'wc-blocks/v1' => 'WC_Rest_API_Blocks_V1',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register REST API routes.
|
||||
*/
|
||||
public function register_rest_routes() {
|
||||
foreach ( $this->get_namespaces() as $namespace => $classname ) {
|
||||
$api = new $classname();
|
||||
$api->includes();
|
||||
|
||||
foreach ( $api->get_controllers() as $controller ) {
|
||||
$this->$controller = new $controller();
|
||||
$this->$controller->register_routes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* V1 API helpers.
|
||||
*
|
||||
* @package WooCommerce/RestAPI/Classes
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Rest_API_V1 class.
|
||||
*/
|
||||
class WC_Rest_API_V1 {
|
||||
|
||||
/**
|
||||
* Include controller classes for this API.
|
||||
*/
|
||||
public function includes() {
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-posts-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-crud-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-terms-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-shipping-zones-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-coupons-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-customer-downloads-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-customers-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-orders-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-order-notes-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-order-refunds-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-attribute-terms-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-attributes-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-categories-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-reviews-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-shipping-classes-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-tags-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-products-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-sales-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-top-sellers-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-reports-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-tax-classes-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-taxes-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-webhook-deliveries-v1-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-webhooks-v1-controller.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of controller classes for this API.
|
||||
*
|
||||
* @return array Array of class names.
|
||||
*/
|
||||
public function get_controllers() {
|
||||
return array(
|
||||
'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',
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* V2 API helpers.
|
||||
*
|
||||
* @package WooCommerce/RestAPI/Classes
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Rest_API_V2 class.
|
||||
*/
|
||||
class WC_Rest_API_V2 {
|
||||
|
||||
/**
|
||||
* Include controller classes for this API.
|
||||
*/
|
||||
public function includes() {
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-posts-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-crud-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-terms-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-shipping-zones-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-coupons-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-customer-downloads-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-customers-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-orders-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-network-orders-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-order-notes-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-order-refunds-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-attribute-terms-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-attributes-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-categories-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-reviews-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-shipping-classes-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-tags-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-products-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-variations-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-sales-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-top-sellers-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-reports-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-settings-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-setting-options-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-zones-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-zone-locations-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-zone-methods-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-tax-classes-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-taxes-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-webhook-deliveries-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-webhooks-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-system-status-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-system-status-tools-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-methods-v2-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-payment-gateways-v2-controller.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of controller classes for this API.
|
||||
*
|
||||
* @return array Array of class names.
|
||||
*/
|
||||
public function get_controllers() {
|
||||
return array(
|
||||
'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',
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* V3 API helpers.
|
||||
*
|
||||
* @package WooCommerce/RestAPI/Classes
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Rest_API_V3 class.
|
||||
*/
|
||||
class WC_Rest_API_V3 {
|
||||
|
||||
/**
|
||||
* Include controller classes for this API.
|
||||
*/
|
||||
public function includes() {
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-posts-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-crud-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-terms-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-shipping-zones-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-coupons-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-customer-downloads-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-customers-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-orders-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-network-orders-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-order-notes-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-order-refunds-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-attribute-terms-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-attributes-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-categories-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-reviews-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-shipping-classes-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-tags-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-products-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-product-variations-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-reports-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-sales-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-top-sellers-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-orders-totals-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-products-totals-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-customers-totals-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-coupons-totals-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-report-reviews-totals-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-settings-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-setting-options-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-zones-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-zone-locations-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-zone-methods-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-tax-classes-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-taxes-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-webhooks-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-system-status-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-system-status-tools-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-shipping-methods-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-payment-gateways-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-data-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-data-continents-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-data-countries-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-data-currencies-controller.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of controller classes for this API.
|
||||
*
|
||||
* @return array Array of class names.
|
||||
*/
|
||||
public function get_controllers() {
|
||||
return array(
|
||||
'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',
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* V1 Blocks API helpers.
|
||||
*
|
||||
* @package WooCommerce/RestAPI/Classes
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Rest_API_Blocks_V1 class.
|
||||
*/
|
||||
class WC_Rest_API_Blocks_V1 {
|
||||
|
||||
/**
|
||||
* Include controller classes for this API.
|
||||
*/
|
||||
public function includes() {
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-posts-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-crud-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-terms-controller.php';
|
||||
include_once dirname( dirname( __FILE__ ) ) . '/abstracts/abstract-wc-rest-shipping-zones-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-blocks-product-attributes-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-blocks-product-attribute-terms-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-blocks-product-categories-controller.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wc-rest-blocks-products-controller.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of controller classes for this API.
|
||||
*
|
||||
* @return array Array of class names.
|
||||
*/
|
||||
public function get_controllers() {
|
||||
return array(
|
||||
'WC_REST_Blocks_Product_Attributes_Controller',
|
||||
'WC_REST_Blocks_Product_Attribute_Terms_Controller',
|
||||
'WC_REST_Blocks_Product_Categories_Controller',
|
||||
'WC_REST_Blocks_Products_Controller',
|
||||
);
|
||||
}
|
||||
}
|
15
phpcs.xml
15
phpcs.xml
|
@ -3,20 +3,14 @@
|
|||
<description>WooCommerce dev PHP_CodeSniffer ruleset.</description>
|
||||
|
||||
<!-- Exclude paths -->
|
||||
<exclude-pattern>tests/cli/</exclude-pattern>
|
||||
<exclude-pattern>tests/</exclude-pattern>
|
||||
<exclude-pattern>apigen/</exclude-pattern>
|
||||
<exclude-pattern>includes/libraries/</exclude-pattern>
|
||||
<exclude-pattern>includes/legacy/</exclude-pattern>
|
||||
<exclude-pattern>includes/api/legacy/</exclude-pattern>
|
||||
<exclude-pattern>includes/api/v1/</exclude-pattern>
|
||||
<exclude-pattern>includes/class-wc-geo-ip.php</exclude-pattern>
|
||||
<exclude-pattern>includes/wc-deprecated-functions.php</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
|
||||
<!-- Configs -->
|
||||
<config name="minimum_supported_wp_version" value="4.7" />
|
||||
<config name="testVersion" value="5.3-" />
|
||||
<config name="testVersion" value="5.6-" />
|
||||
|
||||
<!-- Rules -->
|
||||
<rule ref="WooCommerce-Core" />
|
||||
|
@ -32,7 +26,6 @@
|
|||
</rule>
|
||||
|
||||
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
|
||||
<exclude-pattern>includes/**/abstract-*.php</exclude-pattern>
|
||||
<exclude-pattern>tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
|
@ -40,10 +33,6 @@
|
|||
<exclude-pattern>tests/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
|
||||
<exclude-pattern>tests/e2e-tests/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
|
||||
<exclude-pattern>i18n/</exclude-pattern>
|
||||
</rule>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
TODO
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* Autoload REST API classes.
|
||||
*
|
||||
* @package WooCommerce/Rest_Api
|
||||
*/
|
||||
|
||||
namespace WooCommerce\Rest_Api;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WooCommerce\Rest_Api\Singleton;
|
||||
|
||||
/**
|
||||
* Autoload class.
|
||||
*/
|
||||
class Autoload {
|
||||
use Singleton;
|
||||
|
||||
/**
|
||||
* Hook into WordPress ready to init the REST API as needed.
|
||||
*/
|
||||
public function init() {
|
||||
spl_autoload_register( array( $this, 'autoload' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a class name and turn it into a file name.
|
||||
*
|
||||
* @param string $class Class name.
|
||||
* @return string
|
||||
*/
|
||||
protected function get_file_name_from_class( $class ) {
|
||||
return 'class-' . str_replace( '_', '-', $class ) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Autoloader.
|
||||
*
|
||||
* @param string $class Classname.
|
||||
*/
|
||||
public function autoload( $class ) {
|
||||
$class = str_replace( '\\', DIRECTORY_SEPARATOR, str_replace( '\\' . __NAMESPACE__ . '\\', '', $class ) );
|
||||
$file = $this->get_file_name_from_class( $class );
|
||||
$dir = trailingslashit( dirname( __FILE__ ) );
|
||||
|
||||
// Non-namespaced files.
|
||||
if ( stristr( $class, 'WC_REST_' ) ) {
|
||||
if ( stristr( $class, 'WC_REST_Blocks' ) ) {
|
||||
$subdir = 'wc-blocks/';
|
||||
} elseif ( stristr( $class, '_V1_' ) ) {
|
||||
$subdir = 'v1/';
|
||||
} elseif ( stristr( $class, '_V2_' ) ) {
|
||||
$subdir = 'v2/';
|
||||
} else {
|
||||
$subdir = 'v3/';
|
||||
}
|
||||
|
||||
if ( file_exists( $dir . $subdir . $file ) ) {
|
||||
include $dir . $subdir . $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( file_exists( $dir . $class . '.php' ) ) {
|
||||
include $dir . $class . '.php';
|
||||
return;
|
||||
}
|
||||
|
||||
if ( file_exists( $dir . $file ) ) {
|
||||
include $dir . $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
/**
|
||||
* Load REST API Namespaces.
|
||||
*
|
||||
* @package WooCommerce/Rest_Api
|
||||
*/
|
||||
|
||||
namespace WooCommerce\Rest_Api;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
require_once 'class-singleton.php';
|
||||
require_once 'class-autoload.php';
|
||||
|
||||
use WooCommerce\Rest_Api\Singleton;
|
||||
use WooCommerce\Rest_Api\Autoload;
|
||||
|
||||
/**
|
||||
* Class responsible for loading REST API Namespaces.
|
||||
*/
|
||||
class Server {
|
||||
use Singleton;
|
||||
|
||||
/**
|
||||
* REST API namespaces and endpoints.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $endpoints = array();
|
||||
|
||||
/**
|
||||
* Hook into WordPress ready to init the REST API as needed.
|
||||
*/
|
||||
public function init() {
|
||||
Autoload::instance()->init();
|
||||
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register REST API routes.
|
||||
*/
|
||||
public function register_rest_routes() {
|
||||
foreach ( $this->get_namespaces() as $namespace ) {
|
||||
$this->endpoints[ $namespace ] = array();
|
||||
|
||||
foreach ( $this->get_controllers( $namespace ) as $name => $class ) {
|
||||
$this->endpoints[ $namespace ][ $class ] = new $class();
|
||||
$this->endpoints[ $namespace ][ $class ]->register_routes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API namespaces - new namespaces should be registered here.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_namespaces() {
|
||||
return array(
|
||||
'wc/v1',
|
||||
'wc/v2',
|
||||
'wc/v3',
|
||||
'wc-blocks/v1',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API controllers - new controllers/endpoints should be registered here.
|
||||
*
|
||||
* @param string $namespace Namespace to get controllers for.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_controllers( $namespace ) {
|
||||
switch ( $namespace ) {
|
||||
case 'wc/v1':
|
||||
return array(
|
||||
'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 array(
|
||||
'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 array(
|
||||
'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 array(
|
||||
'WC_REST_Blocks_Product_Attributes_Controller',
|
||||
'WC_REST_Blocks_Product_Attribute_Terms_Controller',
|
||||
'WC_REST_Blocks_Product_Categories_Controller',
|
||||
'WC_REST_Blocks_Products_Controller',
|
||||
);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Abstract singleton class.
|
||||
*
|
||||
* @package WooCommerce/Rest_Api
|
||||
*/
|
||||
|
||||
namespace WooCommerce\Rest_Api;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Singleton trait.
|
||||
*/
|
||||
trait Singleton {
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct() {}
|
||||
|
||||
/**
|
||||
* Get class instance.
|
||||
*
|
||||
* @return object Instance.
|
||||
*/
|
||||
final public static function instance() {
|
||||
if ( null === static::$instance ) {
|
||||
static::$instance = new static();
|
||||
}
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent cloning.
|
||||
*/
|
||||
private function __clone() {}
|
||||
|
||||
/**
|
||||
* Prevent unserializing.
|
||||
*/
|
||||
private function __wakeup() {}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue