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 (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see http://nettephp.com
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    http://nettephp.com/license  Nette license
  15. 15:  * @link       http://nettephp.com
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette
  18. 18:  */
  19. 19:  
  20. 20:  
  21. 21:  
  22. 22: /**
  23. 23:  * Instance iterator filter.
  24. 24:  *
  25. 25:  * @author     David Grudl
  26. 26:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  27. 27:  * @package    Nette
  28. 28:  */
  29. 29: class InstanceFilterIterator extends FilterIterator implements Countable
  30. 30: {
  31. 31:     /** @var string */
  32. 32:     private $type;
  33. 33:  
  34. 34:  
  35. 35:     /**
  36. 36:      * Constructs a filter around another iterator.
  37. 37:      * @param  Iterator 
  38. 38:      * @param  string  class/interface name
  39. 39:      */
  40. 40:     public function __construct(Iterator $iterator$type)
  41. 41:     {
  42. 42:         $this->type $type;
  43. 43:         parent::__construct($iterator);
  44. 44:     }
  45. 45:  
  46. 46:  
  47. 47:  
  48. 48:     /**
  49. 49:      * Expose the current element of the inner iterator?
  50. 50:      * @return bool 
  51. 51:      */
  52. 52:     public function accept()
  53. 53:     {
  54. 54:         return $this->current(instanceof $this->type;
  55. 55:     }
  56. 56:  
  57. 57:  
  58. 58:  
  59. 59:     /**
  60. 60:      * Returns the count of elements.
  61. 61:      * @return int 
  62. 62:      */
  63. 63:     public function count()
  64. 64:     {
  65. 65:         return iterator_count($this);
  66. 66:     }
  67. 67:  
  68. 68: }