WP_CLI

SynopsisValidator::query_spec()privateWP-CLI 1.0

Filters a list of associative arrays, based on a set of key => value arguments.

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

Хуков нет.

Возвращает

Массив.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->query_spec( $args, $operator );
$args(массив) (обязательный)
An array of key => value arguments to match against
$operator(строка)
-
По умолчанию: 'AND'

Код SynopsisValidator::query_spec() WP-CLI 2.8.0-alpha

private function query_spec( $args, $operator = 'AND' ) {
	$operator = strtoupper( $operator );
	$count    = count( $args );
	$filtered = [];

	foreach ( $this->spec as $key => $to_match ) {
		$matched = 0;
		foreach ( $args as $m_key => $m_value ) {
			if ( array_key_exists( $m_key, $to_match ) && $m_value === $to_match[ $m_key ] ) {
				$matched++;
			}
		}

		if ( ( 'AND' === $operator && $matched === $count )
			|| ( 'OR' === $operator && $matched > 0 )
			|| ( 'NOT' === $operator && 0 === $matched ) ) {
				$filtered[ $key ] = $to_match;
		}
	}

	return $filtered;
}