Automattic\WooCommerce\Admin\RemoteInboxNotifications

DataSourcePoller::validate_spec()protectedWC 1.0

Validate the spec.

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

Хуков нет.

Возвращает

true|false. The result of the validation.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_spec( $spec, $url );
$spec(объект) (обязательный)
The spec to validate.
$url(строка) (обязательный)
The url of the feed that provided the spec.

Код DataSourcePoller::validate_spec() WC 8.6.1

protected function validate_spec( $spec, $url ) {
	$logger         = self::get_logger();
	$logger_context = array( 'source' => $url );

	if ( ! isset( $spec->slug ) ) {
		$logger->error(
			'Spec is invalid because the slug is missing in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $spec, true ), $logger_context );

		return false;
	}

	if ( ! isset( $spec->status ) ) {
		$logger->error(
			'Spec is invalid because the status is missing in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $spec, true ), $logger_context );

		return false;
	}

	if ( ! isset( $spec->locales ) || ! is_array( $spec->locales ) ) {
		$logger->error(
			'Spec is invalid because the status is missing or empty in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $spec, true ), $logger_context );

		return false;
	}

	if ( null === SpecRunner::get_locale( $spec->locales ) ) {
		$logger->error(
			'Spec is invalid because the locale could not be retrieved in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $spec, true ), $logger_context );

		return false;
	}

	if ( ! isset( $spec->type ) ) {
		$logger->error(
			'Spec is invalid because the type is missing in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $spec, true ), $logger_context );

		return false;
	}

	if ( isset( $spec->actions ) && is_array( $spec->actions ) ) {
		foreach ( $spec->actions as $action ) {
			if ( ! $this->validate_action( $action, $url ) ) {
				$logger->error(
					'Spec is invalid because an action is invalid in feed',
					$logger_context
				);
				// phpcs:ignore
				$logger->error( print_r( $spec, true ), $logger_context );

				return false;
			}
		}
	}

	if ( isset( $spec->rules ) && is_array( $spec->rules ) ) {
		foreach ( $spec->rules as $rule ) {
			if ( ! isset( $rule->type ) ) {
				$logger->error(
					'Spec is invalid because a rule type is empty in feed',
					$logger_context
				);
				// phpcs:ignore
				$logger->error( print_r( $rule, true ), $logger_context );
				// phpcs:ignore
				$logger->error( print_r( $spec, true ), $logger_context );

				return false;
			}

			$processor = GetRuleProcessor::get_processor( $rule->type );

			if ( ! $processor->validate( $rule ) ) {
				$logger->error(
					'Spec is invalid because a rule is invalid in feed',
					$logger_context
				);
				// phpcs:ignore
				$logger->error( print_r( $rule, true ), $logger_context );
				// phpcs:ignore
				$logger->error( print_r( $spec, true ), $logger_context );

				return false;
			}
		}
	}

	return true;
}