WP_CLI\Traverser
RecursiveDataStructureTraverser::traverse_to
Get an instance of the traverser for the given hierarchical key.
Method of the class: RecursiveDataStructureTraverser{}
No Hooks.
Returns
self.
Usage
$RecursiveDataStructureTraverser = new RecursiveDataStructureTraverser(); $RecursiveDataStructureTraverser->traverse_to( $key_path );
- $key_path(array) (required)
- Hierarchical key path within the current data to traverse to.
RecursiveDataStructureTraverser::traverse_to() RecursiveDataStructureTraverser::traverse to code WP-CLI 2.13.0-alpha
public function traverse_to( array $key_path ) {
$current = array_shift( $key_path );
if ( null === $current ) {
return $this;
}
if ( ! $this->exists( $current ) ) {
$exception = new NonExistentKeyException( "No data exists for key \"{$current}\"" );
$exception->set_traverser( new self( $this->data, $current, $this->parent ) );
throw $exception;
}
foreach ( $this->data as $key => &$key_data ) {
if ( $key === $current ) {
$traverser = new self( $key_data, $key, $this );
return $traverser->traverse_to( $key_path );
}
}
}