Automattic\WooCommerce\Api\Infrastructure

ResolverHelpers::build_authorize_call_argsprivate staticWC 1.0

Build the positional/named argument list for an attribute's authorize() method based on which opt-in slots its signature declares.

The principal is always passed first (positionally) when the method declares a non-_-prefixed parameter; infrastructure parameters ($_metadata, $_args, $_parent) are passed as named arguments so the attribute can omit any subset without affecting the call shape.

Method of the class: ResolverHelpers{}

No Hooks.

Returns

Array. mixed> Positional principal first (if any), then named infra slots. Use with ... spread.

Usage

$result = ResolverHelpers::build_authorize_call_args( $method, $principal, $metadata, $args, $parent ): array;
$method(ReflectionMethod) (required)
The attribute's authorize() method.
$principal(object) (required)
The resolved principal to pass when the method takes one.
$metadata(array) (required)
Value for $_metadata (passed if the method declares it).
$args(array) (required)
Value for $_args (passed if the method declares it).
$parent(mixed) (required)
Value for $_parent (passed if the method declares it).

ResolverHelpers::build_authorize_call_args() code WC 11.0.0

private static function build_authorize_call_args( \ReflectionMethod $method, object $principal, array $metadata, array $args, mixed $parent ): array {
	$call_args = array();
	foreach ( $method->getParameters() as $param ) {
		$name = $param->getName();
		if ( '_metadata' === $name ) {
			$call_args['_metadata'] = $metadata;
		} elseif ( '_args' === $name ) {
			$call_args['_args'] = $args;
		} elseif ( '_parent' === $name ) {
			$call_args['_parent'] = $parent;
		} elseif ( '' === $name || '_' !== $name[0] ) {
			// Principal — positional, must be the first entry in the spread.
			array_unshift( $call_args, $principal );
		}
	}
	return $call_args;
}