Automattic\WooCommerce\Admin\RemoteInboxNotifications

RuleEvaluator::evaluate()publicWC 1.0

Evaluate the given rules as an AND operation - return false early if a rule evaluates to false.

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

No Hooks.

Return

true|false. The result of the operation.

Usage

$RuleEvaluator = new RuleEvaluator();
$RuleEvaluator->evaluate( $rules, $stored_state, $logger_args );
$rules(array|object) (required)
The rule or rules being processed.
$stored_state(object|null)
Stored state.
Default: null
$logger_args(array)
Arguments for the event logger. slug is required.
Default: array()

Code of RuleEvaluator::evaluate() WC 7.1.0

public function evaluate( $rules, $stored_state = null, $logger_args = array() ) {

	if ( is_bool( $rules ) ) {
		return $rules;
	}

	if ( ! is_array( $rules ) ) {
		$rules = array( $rules );
	}

	if ( 0 === count( $rules ) ) {
		return false;
	}

	$evaluation_logger = null;

	if ( count( $logger_args ) ) {
		if ( ! array_key_exists( 'slug', $logger_args ) ) {
			throw new \InvalidArgumentException( 'Missing required field: slug in $logger_args.' );
		}

		array_key_exists( 'source', $logger_args ) ? $source = $logger_args['source'] : $source = null;

		$evaluation_logger = new EvaluationLogger( $logger_args['slug'], $source );
	}

	foreach ( $rules as $rule ) {
		if ( ! is_object( $rule ) ) {
			return false;
		}

		$processor        = $this->get_rule_processor->get_processor( $rule->type );
		$processor_result = $processor->process( $rule, $stored_state );
		$evaluation_logger && $evaluation_logger->add_result( $rule->type, $processor_result );

		if ( ! $processor_result ) {
			$evaluation_logger && $evaluation_logger->log();
			return false;
		}
	}

	$evaluation_logger && $evaluation_logger->log();

	return true;
}