WC_CLI_REST_Command::__construct( string $name, string $route, array $schema )

Sets up REST Command.


Description Description


Parameters Parameters

$name

(Required) Name of endpoint object (comes from schema).

$route

(Required) Path to route of this endpoint.

$schema

(Required) Schema object.


Top ↑

Source Source

File: includes/cli/class-wc-cli-rest-command.php

	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];
			}
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.