Skip to content

Commit c6b7d7b

Browse files
committed
PHPLIB-45: Construct CollectionInfoLegacyIterator from Traversable
1 parent f869365 commit c6b7d7b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Model/CollectionInfoLegacyIterator.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33
namespace MongoDB\Model;
44

55
use FilterIterator;
6+
use Iterator;
7+
use IteratorIterator;
8+
use Traversable;
69

710
class CollectionInfoLegacyIterator extends FilterIterator implements CollectionInfoIterator
811
{
12+
/**
13+
* Constructor.
14+
*
15+
* @param Traversable $iterator
16+
*/
17+
public function __construct(Traversable $iterator)
18+
{
19+
/* FilterIterator requires an Iterator, so wrap all other Traversables
20+
* with an IteratorIterator as a convenience.
21+
*/
22+
if ( ! $iterator instanceof Iterator) {
23+
$iterator = new IteratorIterator($iterator);
24+
}
25+
26+
parent::__construct($iterator);
27+
}
28+
929
/**
1030
* Return the current element as a CollectionInfo instance.
1131
*

0 commit comments

Comments
 (0)