WP_CLI\Iterators

Transform{}WP-CLI 1.0

Applies one or more callbacks to an item before returning it.

No Hooks.

Usage

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

Methods

  1. public add_transform( $fn )
  2. public current()

Transform{} code WP-CLI 2.8.0-alpha

class Transform extends IteratorIterator {

	private $transformers = [];

	public function add_transform( $fn ) {
		$this->transformers[] = $fn;
	}

	public function current() {
		$value = parent::current();

		foreach ( $this->transformers as $fn ) {
			$value = call_user_func( $fn, $value );
		}

		return $value;
	}
}