PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Nette/InstanceFilterIterator.php

https://github.com/DocX/nette
PHP | 70 lines | 18 code | 14 blank | 38 comment | 0 complexity | afa6549411d6ca5ccb7782f57013241d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Nette Framework
  4. *
  5. * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  6. *
  7. * This source file is subject to the "Nette license" that is bundled
  8. * with this package in the file license.txt.
  9. *
  10. * For more information please see http://nettephp.com
  11. *
  12. * @copyright Copyright (c) 2004, 2009 David Grudl
  13. * @license http://nettephp.com/license Nette license
  14. * @link http://nettephp.com
  15. * @category Nette
  16. * @package Nette
  17. */
  18. /*namespace Nette;*/
  19. /**
  20. * Instance iterator filter.
  21. *
  22. * @author David Grudl
  23. * @copyright Copyright (c) 2004, 2009 David Grudl
  24. * @package Nette
  25. */
  26. class InstanceFilterIterator extends /*\*/FilterIterator implements /*\*/Countable
  27. {
  28. /** @var string */
  29. private $type;
  30. /**
  31. * Constructs a filter around another iterator.
  32. * @param Iterator
  33. * @param string class/interface name
  34. */
  35. public function __construct(/*\*/Iterator $iterator, $type)
  36. {
  37. $this->type = $type;
  38. parent::__construct($iterator);
  39. }
  40. /**
  41. * Expose the current element of the inner iterator?
  42. * @return bool
  43. */
  44. public function accept()
  45. {
  46. return $this->current() instanceof $this->type;
  47. }
  48. /**
  49. * Returns the count of elements.
  50. * @return int
  51. */
  52. public function count()
  53. {
  54. return iterator_count($this);
  55. }
  56. }