public function __construct(RecursiveIterator $it, $regex) { $this->regex = $regex; parent::__construct($it, $this->regex); }
/** * RegexFilter constructor. * @param \RecursiveIterator $iterator * @param string $regex */ public function __construct(RecursiveIterator $iterator, $regex) { $this->iterator = $iterator; $this->regex = $this->toRegex($regex); parent::__construct($iterator, $this->regex); }
function accept() { return $this->hasChildren() || parent::accept(); }
<?php $data = array(array('tet3', 'test4', 'test5'), array('tet2', 'test1')); $iterator = new RecursiveRegexIterator(new RecursiveArrayIterator($data), '/^test/', RecursiveRegexIterator::ALL_MATCHES); foreach ($iterator as $value) { foreach ($iterator->getChildren() as $value) { echo $value, PHP_EOL; } }
<?php $array = new ArrayIterator(array('a', array('b', 'c'))); $regex = new RegexIterator($array, '/Array/'); foreach ($regex as $match) { var_dump($match); } $rArrayIterator = new RecursiveArrayIterator(array('test1', array('tet3', 'test4', 'test5'))); $rRegexIterator = new RecursiveRegexIterator($rArrayIterator, '/^(t)est(\\d*)/', RecursiveRegexIterator::ALL_MATCHES, 0, PREG_PATTERN_ORDER); foreach ($rRegexIterator as $key1 => $value1) { if ($rRegexIterator->hasChildren()) { // print all children echo "Children: "; foreach ($rRegexIterator->getChildren() as $key => $value) { print_r($value); } echo "\n"; } else { echo "No children "; print_r($value1); echo "\n"; } }
<?php // https://github.com/php/php-src/pull/865 $arr = new RecursiveArrayIterator([['test2', 'test3']]); $regex = new RecursiveRegexIterator($arr, '/^test/', RecursiveRegexIterator::ALL_MATCHES, 1, 2); $child = $regex->getChildren(); var_dump(get_class($child), $child->getMode(), $child->getFlags(), $child->getPregFlags());
/** * Simply invert the accept() function * */ public function accept() { return !parent::accept(); }