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