for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Ddeboer\DataImport\Reader;
/**
* Use a class implementing both \Iterator and \Countable as a reader
*
* This class uses count() on iterators implementing \Countable interface
* and iterator_count in any further cases
* Be careful! iterator_count iterates through the whole iterator loading every data into the memory (for example from streams)
* It is not recommended for very big datasets.
* @author Márk Sági-Kazár <[email protected]>
*/
class CountableIteratorReader extends IteratorReader implements CountableReader
{
* {@inheritdoc}
public function count()
$iterator = $this->getInnerIterator();
if ($iterator instanceof \Countable) {
return count($iterator);
}
return iterator_count($iterator);