Source for file InstanceFilterIterator.php

Documentation is available at InstanceFilterIterator.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  7. 7:  * @license    http://nettephp.com/license  Nette license
  8. 8:  * @link       http://nettephp.com
  9. 9:  * @category   Nette
  10. 10:  * @package    Nette
  11. 11:  */
  12. 12:  
  13. 13:  
  14. 14:  
  15. 15: /**
  16. 16:  * Instance iterator filter.
  17. 17:  *
  18. 18:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  19. 19:  * @package    Nette
  20. 20:  */
  21. 21: class InstanceFilterIterator extends FilterIterator implements Countable
  22. 22: {
  23. 23:     /** @var string */
  24. 24:     private $type;
  25. 25:  
  26. 26:  
  27. 27:     /**
  28. 28:      * Constructs a filter around another iterator.
  29. 29:      * @param  Iterator 
  30. 30:      * @param  string  class/interface name
  31. 31:      */
  32. 32:     public function __construct(Iterator $iterator$type)
  33. 33:     {
  34. 34:         $this->type $type;
  35. 35:         parent::__construct($iterator);
  36. 36:     }
  37. 37:  
  38. 38:  
  39. 39:  
  40. 40:     /**
  41. 41:      * Expose the current element of the inner iterator?
  42. 42:      * @return bool 
  43. 43:      */
  44. 44:     public function accept()
  45. 45:     {
  46. 46:         return $this->current(instanceof $this->type;
  47. 47:     }
  48. 48:  
  49. 49:  
  50. 50:  
  51. 51:     /**
  52. 52:      * Returns the count of elements.
  53. 53:      * @return int 
  54. 54:      */
  55. 55:     public function count()
  56. 56:     {
  57. 57:         return iterator_count($this);
  58. 58:     }
  59. 59:  
  60. 60: }