HosipLan

Untitled

Aug 11th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This file is part of the Kdyby (http://www.kdyby.org)
  5.  *
  6.  * Copyright (c) 2008, 2011 Filip Procházka ([email protected])
  7.  *
  8.  * @license http://www.kdyby.org/license
  9.  */
  10.  
  11. namespace Kdyby\Iterators;
  12.  
  13. use Kdyby;
  14. use Nette;
  15.  
  16.  
  17.  
  18. /**
  19.  * @author Filip Procházka
  20.  */
  21. class CollectIterator extends \FilterIterator
  22. {
  23.  
  24.     /** @var callback[] */
  25.     private $collector;
  26.  
  27.  
  28.  
  29.     /**
  30.      * @param callable $callback
  31.      * @return CollectIterator
  32.      */
  33.     public function collect($callback)
  34.     {
  35.         $this->collector[] = $callback;
  36.         return $this;
  37.     }
  38.  
  39.  
  40.  
  41.     /**
  42.      * @return boolean
  43.      */
  44.     public function accept()
  45.     {
  46.         foreach ($this->collector as $filter) {
  47.             if (!$filter($this)) {
  48.                 return FALSE;
  49.             }
  50.         }
  51.  
  52.         return TRUE;
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment