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: */
11:
12: namespace Nette\Iterators;
13:
14: use Nette;
15:
16:
17: /**
18: * Instance iterator filter.
19: *
20: * @author David Grudl
21: */
22: class InstanceFilter extends \FilterIterator implements \Countable
23: {
24: /** @var string */
25: private $type;
26:
27:
28: /**
29: * Constructs a filter around another iterator.
30: * @param \Iterator
31: * @param string class/interface name
32: */
33: public function __construct(\Iterator $iterator, $type)
34: {
35: $this->type = $type;
36: parent::__construct($iterator);
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: * Returns the count of elements.
52: * @return int
53: */
54: public function count()
55: {
56: return iterator_count($this);
57: }
58:
59: }
60: