WC_CLI_REST_Command::__construct()publicWC 1.0

Sets up REST Command.

Method of the class: WC_CLI_REST_Command{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_CLI_REST_Command = new WC_CLI_REST_Command();
$WC_CLI_REST_Command->__construct( $name, $route, $schema );
$name(string) (required)
Name of endpoint object (comes from schema).
$route(string) (required)
Path to route of this endpoint.
$schema(array) (required)
Schema object.

WC_CLI_REST_Command::__construct() code WC 8.7.0

public function __construct( $name, $route, $schema ) {
	$this->name = $name;

	preg_match_all( '#\([^\)]+\)#', $route, $matches );
	$first_match  = $matches[0];
	$resource_id  = ! empty( $matches[0] ) ? array_pop( $matches[0] ) : null;
	$this->route  = rtrim( $route );
	$this->schema = $schema;

	$this->resource_identifier = $resource_id;
	if ( in_array( $name, $this->routes_with_parent_id, true ) ) {
		$is_singular = substr( $this->route, - strlen( $resource_id ) ) === $resource_id;
		if ( ! $is_singular ) {
			$this->resource_identifier = $first_match[0];
		}
	}
}