1: <?php
2:
3: /**
4: * This file is part of the Nette Framework.
5: *
6: * Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)
7: *
8: * This source file is subject to the "Nette license", and/or
9: * GPL license. For more information please see http://nette.org
10: * @package Nette
11: */
12:
13:
14:
15: /**
16: * Instance iterator filter.
17: *
18: * @author David Grudl
19: */
20: class InstanceFilterIterator extends FilterIterator implements Countable
21: {
22: /** @var string */
23: private $type;
24:
25:
26: /**
27: * Constructs a filter around another iterator.
28: * @param Iterator
29: * @param string class/interface name
30: */
31: public function __construct(Iterator $iterator, $type)
32: {
33: $this->type = $type;
34: parent::__construct($iterator);
35: }
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: /**
51: * Returns the count of elements.
52: * @return int
53: */
54: public function count()
55: {
56: return iterator_count($this);
57: }
58:
59: }
60: