Automattic\WooCommerce\Admin\RemoteInboxNotifications

TransformerService::apply()public staticWC 1.0

Apply transformers to the given value.

Method of the class: TransformerService{}

No Hooks.

Return

Mixed|null.

Usage

$result = TransformerService::apply( $target_value, $transformer_configs, $default );
$target_value(mixed) (required)
a value to transform.
$transformer_configs(array) (required)
transform configuration.
$default(string) (required)
default value.

TransformerService::apply() code WC 8.6.1

public static function apply( $target_value, array $transformer_configs, $default ) {
	foreach ( $transformer_configs as $transformer_config ) {
		if ( ! isset( $transformer_config->use ) ) {
			throw new InvalidArgumentException( 'Missing required config value: use' );
		}

		if ( ! isset( $transformer_config->arguments ) ) {
			$transformer_config->arguments = null;
		}

		$transformer = self::create_transformer( $transformer_config->use );
		if ( null === $transformer ) {
			throw new InvalidArgumentException( "Unable to find a transformer by name: {$transformer_config->use}" );
		}

		$transformed_value = $transformer->transform( $target_value, $transformer_config->arguments, $default );
		// if the transformer returns null, then return the previously transformed value.
		if ( null === $transformed_value ) {
			return $target_value;
		}

		$target_value = $transformed_value;
	}

	return $target_value;
}