WP_CLI
SynopsisValidator::validate_assoc()
Check that all required keys are present and that they have values.
Method of the class: SynopsisValidator{}
No Hooks.
Return
Array
.
Usage
$SynopsisValidator = new SynopsisValidator(); $SynopsisValidator->validate_assoc( $assoc_args );
- $assoc_args(array) (required)
- Parameters passed to command.
SynopsisValidator::validate_assoc() SynopsisValidator::validate assoc code WP-CLI 2.8.0-alpha
public function validate_assoc( $assoc_args ) { $assoc_spec = $this->query_spec( [ 'type' => 'assoc', ] ); $errors = [ 'fatal' => [], 'warning' => [], ]; $to_unset = []; foreach ( $assoc_spec as $param ) { $key = $param['name']; if ( ! isset( $assoc_args[ $key ] ) ) { if ( ! $param['optional'] ) { $errors['fatal'][ $key ] = "missing --$key parameter"; } } else { if ( true === $assoc_args[ $key ] && ! $param['value']['optional'] ) { $error_type = ( ! $param['optional'] ) ? 'fatal' : 'warning'; $errors[ $error_type ][ $key ] = "--$key parameter needs a value"; $to_unset[] = $key; } } } return [ $errors, $to_unset ]; }