Permalink
Browse files

added iterators Filter & RecursiveFilter

  • Loading branch information...
dg committed Jan 21, 2017
1 parent a1edf18 commit 5049688e79acc8cb3f6a547fe661863cf5316dee
Showing with 69 additions and 0 deletions.
  1. +35 −0 src/Iterators/Filter.php
  2. +34 −0 src/Iterators/RecursiveFilter.php
@@ -0,0 +1,35 @@
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Nette\Iterators;
use Nette;
/**
* CallbackFilterIterator for PHP < 5.4.
* @deprecated use CallbackFilterIterator
*/
class Filter extends \FilterIterator
{
/** @var callable */
protected $callback;
public function __construct(\Iterator $iterator, $callback)
{
trigger_error(__CLASS__ . ' is deprecated, use CallbackFilterIterator.', E_USER_WARNING);
parent::__construct($iterator);
$this->callback = Nette\Utils\Callback::check($callback);
}
public function accept()
{
return call_user_func($this->callback, $this->current(), $this->key(), $this);
}
}
@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Nette\Iterators;
/**
* RecursiveCallbackFilterIterator for PHP < 5.4.
* @deprecated use RecursiveCallbackFilterIterator
*/
class RecursiveFilter extends Filter implements \RecursiveIterator
{
public function __construct(\RecursiveIterator $iterator, $callback)
{
trigger_error(__CLASS__ . ' is deprecated, use RecursiveCallbackFilterIterator.', E_USER_WARNING);
parent::__construct($iterator, $callback);
}
public function hasChildren()
{
return $this->getInnerIterator()->hasChildren();
}
public function getChildren()
{
return new static($this->getInnerIterator()->getChildren(), $this->callback);
}
}

0 comments on commit 5049688

Please sign in to comment.