WC_CLI_REST_Command
in package
Main Command for WooCommere CLI.
Since a lot of WC operations can be handled via the REST API, we base our CLI off of Restful to generate commands for each WooCommerce REST API endpoint so most of the logic is shared.
Forked from wp-cli/restful (by Daniel Bachhuber, released under the MIT license https://opensource.org/licenses/MIT). https://github.com/wp-cli/restful
Tags
Table of Contents
- $routes_with_parent_id : array
- Endpoints that have a parent ID.
- $name : string
- Name of command/endpoint object.
- $resource_identifier : int
- Main resource ID.
- $route : string
- Endpoint route.
- $schema : array
- Schema for command.
- $supported_ids : array
- List of supported IDs and their description (name => desc).
- __construct() : mixed
- Sets up REST Command.
- create_item() : mixed
- Create a new item.
- delete_item() : mixed
- Delete an existing item.
- get_item() : mixed
- Get a single item.
- get_supported_ids() : array
- Returns an ID of supported ID arguments (things like product_id, order_id, etc) that we should look for in addition to id.
- list_items() : mixed
- List all items.
- set_supported_ids() : mixed
- Passes supported ID arguments (things like product_id, order_id, etc) that we should look for in addition to id.
- update_item() : mixed
- Update an existing item.
- decode_json() : array
- JSON can be passed in some more complicated objects, like the payment gateway settings array.
- get_formatter() : Formatter
- Get Formatter object based on supplied parameters.
- do_request() : array
- Do a REST Request
- get_context_fields() : array
- Get a list of fields present in a given context
- get_filled_route() : string
- Get the route for this resource
- limit_item_to_fields() : array
- Reduce an item to specific fields.
Properties
$routes_with_parent_id
Endpoints that have a parent ID.
protected
array
$routes_with_parent_id
= array('customer_download', 'product_review', 'order_note', 'shop_order_refund')
Ex: Product reviews, which has a product ID and a review ID.
$name
Name of command/endpoint object.
private
string
$name
$resource_identifier
Main resource ID.
private
int
$resource_identifier
$route
Endpoint route.
private
string
$route
$schema
Schema for command.
private
array
$schema
$supported_ids
List of supported IDs and their description (name => desc).
private
array
$supported_ids
= array()
Methods
__construct()
Sets up REST Command.
public
__construct(string $name, string $route, array $schema) : mixed
Parameters
- $name : string
-
Name of endpoint object (comes from schema).
- $route : string
-
Path to route of this endpoint.
- $schema : array
-
Schema object.
Return values
mixedcreate_item()
Create a new item.
public
create_item(array $args, array $assoc_args) : mixed
Parameters
- $args : array
-
WP-CLI positional arguments.
- $assoc_args : array
-
WP-CLI associative arguments.
Tags
Return values
mixeddelete_item()
Delete an existing item.
public
delete_item(array $args, array $assoc_args) : mixed
Parameters
- $args : array
-
WP-CLI positional arguments.
- $assoc_args : array
-
WP-CLI associative arguments.
Tags
Return values
mixedget_item()
Get a single item.
public
get_item(array $args, array $assoc_args) : mixed
Parameters
- $args : array
-
WP-CLI positional arguments.
- $assoc_args : array
-
WP-CLI associative arguments.
Tags
Return values
mixedget_supported_ids()
Returns an ID of supported ID arguments (things like product_id, order_id, etc) that we should look for in addition to id.
public
get_supported_ids() : array
Return values
arraylist_items()
List all items.
public
list_items(array $args, array $assoc_args) : mixed
Parameters
- $args : array
-
WP-CLI positional arguments.
- $assoc_args : array
-
WP-CLI associative arguments.
Tags
Return values
mixedset_supported_ids()
Passes supported ID arguments (things like product_id, order_id, etc) that we should look for in addition to id.
public
set_supported_ids([array $supported_ids = array() ]) : mixed
Parameters
- $supported_ids : array = array()
-
List of supported IDs.
Return values
mixedupdate_item()
Update an existing item.
public
update_item(array $args, array $assoc_args) : mixed
Parameters
- $args : array
-
WP-CLI positional arguments.
- $assoc_args : array
-
WP-CLI associative arguments.
Tags
Return values
mixeddecode_json()
JSON can be passed in some more complicated objects, like the payment gateway settings array.
protected
decode_json(array $arr) : array
This function decodes the json (if present) and tries to get it's value.
Parameters
- $arr : array
-
Array that will be scanned for JSON encoded values.
Return values
arrayget_formatter()
Get Formatter object based on supplied parameters.
protected
get_formatter(array &$assoc_args) : Formatter
Parameters
- $assoc_args : array
-
Parameters passed to command. Determines formatting.
Return values
Formatterdo_request()
Do a REST Request
private
do_request(string $method, string $route, array $assoc_args) : array
Parameters
- $method : string
-
Request method. Examples: 'POST', 'PUT', 'DELETE' or 'GET'.
- $route : string
-
Resource route.
- $assoc_args : array
-
Associative arguments passed to the originating WP-CLI command.
Return values
arrayget_context_fields()
Get a list of fields present in a given context
private
get_context_fields(string $context) : array
Parameters
- $context : string
-
Scope under which the request is made. Determines fields present in response.
Return values
arrayget_filled_route()
Get the route for this resource
private
get_filled_route([array $args = array() ]) : string
Parameters
- $args : array = array()
-
Positional arguments passed to the originating WP-CLI command.
Return values
stringlimit_item_to_fields()
Reduce an item to specific fields.
private
static limit_item_to_fields(array $item, array $fields) : array
Parameters
- $item : array
-
Item to reduce.
- $fields : array
-
Fields to keep.