Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This file is part of the Kdyby (http://www.kdyby.org)
- *
- * Copyright (c) 2008, 2011 Filip Procházka ([email protected])
- *
- * @license http://www.kdyby.org/license
- */
- namespace Kdyby\Iterators;
- use Kdyby;
- use Nette;
- /**
- * @author Filip Procházka
- */
- class CollectIterator extends \FilterIterator
- {
- /** @var callback[] */
- private $collector;
- /**
- * @param callable $callback
- * @return CollectIterator
- */
- public function collect($callback)
- {
- $this->collector[] = $callback;
- return $this;
- }
- /**
- * @return boolean
- */
- public function accept()
- {
- foreach ($this->collector as $filter) {
- if (!$filter($this)) {
- return FALSE;
- }
- }
- return TRUE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment