WP_CLI\Iterators
Transform{}└─ IteratorIterator
Applies one or more callbacks to an item before returning it.
No Hooks.
Usage
$Transform = new Transform(); // use class methods
Methods
- public add_transform( $fn )
- public current()
Transform{} Transform{} code WP-CLI 2.13.0-alpha
class Transform extends IteratorIterator {
private $transformers = [];
public function add_transform( $fn ) {
$this->transformers[] = $fn;
}
#[\ReturnTypeWillChange]
public function current() {
$value = parent::current();
foreach ( $this->transformers as $fn ) {
$value = call_user_func( $fn, $value );
}
return $value;
}
}