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