1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://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
11: */
12:
13:
14:
15: /**
16: * Instance iterator filter.
17: *
18: * @author David Grudl
19: * @package Nette
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 NIterator
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: /**
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:
50:
51: /**
52: * Returns the count of elements.
53: * @return int
54: */
55: public function count()
56: {
57: return iterator_count($this);
58: }
59:
60: }
61: