Deprecate API Package class because its not a package anymore.

This commit is contained in:
vedanshujain 2020-07-30 00:10:14 +05:30
parent cfe357cfb2
commit 1d782f025e
4 changed files with 43 additions and 14 deletions

View File

@ -1,5 +1,7 @@
<?php
/**
* Deprecated notice: This class is deprecated as of version 4.5.0. WooCommerce API is now part of core and not packaged seperately.
*
* Returns information about the package and handles init.
*
* @package Automattic/WooCommerce/RestApi
@ -11,38 +13,48 @@ defined( 'ABSPATH' ) || exit;
/**
* Main package class.
*
* @deprecated Use \Automattic\WooCommerce\RestApi\Server directly.
*/
class Package {
/**
* Version.
*
* @deprecated since 4.5.0. This tracks WooCommerce version now.
* @var string
*/
const VERSION = WC_VERSION;
/**
* Init the package - load the REST API Server class.
*
* @deprecated since 4.5.0. Directly call Automattic\WooCommerce\RestApi\Server::instance()->init()
*/
public static function init() {
wc_deprecated_function( 'Automattic\WooCommerce\RestApi\Server::instance()->init()', '4.5.0' );
\Automattic\WooCommerce\RestApi\Server::instance()->init();
}
/**
* Return the version of the package.
*
* @deprecated since 4.5.0. This tracks WooCommerce version now.
* @return string
*/
public static function get_version() {
return self::VERSION;
wc_deprecated_function( 'WC()->version', '4.5.0' );
return WC()->version;
}
/**
* Return the path to the package.
*
* @deprecated since 4.5.0. Directly call Automattic\WooCommerce\RestApi\Server::get_path()
* @return string
*/
public static function get_path() {
return dirname( __DIR__ );
wc_deprecated_function( 'Automattic\WooCommerce\RestApi\Server::get_path()', '4.5.0' );
return \Automattic\WooCommerce\RestApi\Server::get_path();
}
}

View File

@ -22,7 +22,7 @@ class Server {
*
* @var array
*/
protected $controllers = [];
protected $controllers = array();
/**
* Hook into WordPress ready to init the REST API as needed.
@ -51,11 +51,11 @@ class Server {
protected function get_rest_namespaces() {
return apply_filters(
'woocommerce_rest_api_get_rest_namespaces',
[
array(
'wc/v1' => $this->get_v1_controllers(),
'wc/v2' => $this->get_v2_controllers(),
'wc/v3' => $this->get_v3_controllers(),
]
)
);
}
@ -65,7 +65,7 @@ class Server {
* @return array
*/
protected function get_v1_controllers() {
return [
return array(
'coupons' => 'WC_REST_Coupons_V1_Controller',
'customer-downloads' => 'WC_REST_Customer_Downloads_V1_Controller',
'customers' => 'WC_REST_Customers_V1_Controller',
@ -86,7 +86,7 @@ class Server {
'taxes' => 'WC_REST_Taxes_V1_Controller',
'webhooks' => 'WC_REST_Webhooks_V1_Controller',
'webhook-deliveries' => 'WC_REST_Webhook_Deliveries_V1_Controller',
];
);
}
/**
@ -95,7 +95,7 @@ class Server {
* @return array
*/
protected function get_v2_controllers() {
return [
return array(
'coupons' => 'WC_REST_Coupons_V2_Controller',
'customer-downloads' => 'WC_REST_Customer_Downloads_V2_Controller',
'customers' => 'WC_REST_Customers_V2_Controller',
@ -127,7 +127,7 @@ class Server {
'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',
];
);
}
/**
@ -136,7 +136,7 @@ class Server {
* @return array
*/
protected function get_v3_controllers() {
return [
return array(
'coupons' => 'WC_REST_Coupons_Controller',
'customer-downloads' => 'WC_REST_Customer_Downloads_Controller',
'customers' => 'WC_REST_Customers_Controller',
@ -176,6 +176,15 @@ class Server {
'data-continents' => 'WC_REST_Data_Continents_Controller',
'data-countries' => 'WC_REST_Data_Countries_Controller',
'data-currencies' => 'WC_REST_Data_Currencies_Controller',
];
);
}
/**
* Return the path to the package.
*
* @return string
*/
public static function get_path() {
return dirname( __DIR__ );
}
}

View File

@ -39,6 +39,14 @@ class WC_API extends WC_Legacy_API {
if ( ! $this->is_rest_api_loaded() ) {
return null;
}
if ( method_exists( \Automattic\WooCommerce\RestApi\Server::class, 'get_path' ) ) {
$path = \Automattic\WooCommerce\RestApi\Server::get_path();
if ( 0 === strpos( $path, __DIR__ ) ) {
// We are loading API from included version.
return WC()->version;
}
}
// We are loading API from external plugin.
return \Automattic\WooCommerce\RestApi\Package::get_version();
}
@ -52,7 +60,7 @@ class WC_API extends WC_Legacy_API {
if ( ! $this->is_rest_api_loaded() ) {
return null;
}
return \Automattic\WooCommerce\RestApi\Package::get_path();
return \Automattic\WooCommerce\RestApi\Server::get_path();
}
/**
@ -62,7 +70,7 @@ class WC_API extends WC_Legacy_API {
* @return boolean
*/
protected function is_rest_api_loaded() {
return class_exists( '\Automattic\WooCommerce\RestApi\Package', false );
return class_exists( '\Automattic\WooCommerce\RestApi\Server', false );
}
/**

View File

@ -303,7 +303,7 @@ final class WooCommerce {
* Load REST API.
*/
public function load_rest_api() {
\Automattic\WooCommerce\RestApi\Package::init();
\Automattic\WooCommerce\RestApi\Server::instance()->init();
}
/**