/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Collection/Iterator
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Collection/Iterator/ExtractIterator.php (2952B)
['body' => 'cool', 'user' => ['name' => 'Mark']],
* ['comment' => ['body' => 'very cool', 'user' => ['name' => 'Renan']]
* ];
* $extractor = new ExtractIterator($items, 'comment.user.name'');
* ```
*
* @param iterable $items The list of values to iterate
* @param string|callable $path A dot separated path of column to follow
* so that the final one can be returned or a callable that will take care
* of doing that.
*/
public function __construct(iterable $items, $path)
{
$this->_extractor = $this->_propertyExtractor($path);
parent::__construct($items);
}
/**
* Returns the column value defined in $path or null if the path could not be
* followed
*
* @return mixed
*/
public function current()
{
$extractor = $this->_extractor;
return $extractor(parent::current());
}
/**
* @inheritDoc
*/
public function unwrap(): Traversable
{
$iterator = $this->getInnerIterator();
if ($iterator instanceof CollectionInterface) {
$iterator = $iterator->unwrap();
}
if (get_class($iterator) !== ArrayIterator::class) {
return $this;
}
// ArrayIterator can be traversed strictly.
// Let's do that for performance gains
$callback = $this->_extractor;
$res = [];
foreach ($iterator->getArrayCopy() as $k => $v) {
$res[$k] = $callback($v);
}
return new ArrayIterator($res);
}
}