Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers

ArraySearch{}WC 1.0

Searches a given a given value in the array.

Хуков нет.

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

$ArraySearch = new ArraySearch();
// use class methods

Методы

  1. public transform( $value, stdClass $arguments = null, $default = null )
  2. public validate( stdClass $arguments = null )

Заметки

  • Пакет: Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers

Код ArraySearch{} WC 8.7.0

class ArraySearch implements TransformerInterface {
	/**
	 * Search a given value in the array.
	 *
	 * @param mixed         $value a value to transform.
	 * @param stdClass|null $arguments required argument 'value'.
	 * @param string|null   $default default value.
	 *
	 * @throws InvalidArgumentException Throws when the required 'value' is missing.
	 *
	 * @return mixed|null
	 */
	public function transform( $value, stdClass $arguments = null, $default = null ) {
		if ( ! is_array( $value ) ) {
			return $default;
		}

		$key = array_search( $arguments->value, $value, true );
		if ( false !== $key ) {
			return $value[ $key ];
		}

		return null;
	}

	/**
	 * Validate Transformer arguments.
	 *
	 * @param stdClass|null $arguments arguments to validate.
	 *
	 * @return mixed
	 */
	public function validate( stdClass $arguments = null ) {
		if ( ! isset( $arguments->value ) ) {
			return false;
		}

		return true;
	}
}