CLI_Alias_Command::validate_input()privateWP-CLI 1.0

Validate input of passed arguments.

Метод класса: CLI_Alias_Command{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->validate_input( $assoc_args, $grouping );
$assoc_args(array) (required)
Arguments array.
$grouping(string) (required)
Grouping argument value.

Код CLI_Alias_Command::validate_input() WP-CLI 2.7.0-alpha

private function validate_input( $assoc_args, $grouping ) {
	// Check if valid arguments were passed.
	$arg_match = preg_grep( '/^set-(\w+)/i', array_keys( $assoc_args ) );

	// Verify passed-arguments.
	if ( empty( $grouping ) && empty( $arg_match ) ) {
		WP_CLI::error( 'No valid arguments passed.' );
	}

	// Check whether passed arguments contain value or not.
	$assoc_arg_values = array_filter( array_intersect_key( $assoc_args, array_flip( $arg_match ) ) );

	if ( empty( $grouping ) && empty( $assoc_arg_values ) ) {
		WP_CLI::error( 'No value passed to arguments.' );
	}
}