for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Jasny\Container\Loader;
/**
* Base class for loader using two iterators.
*/
abstract class AbstractLoader implements \OuterIterator
{
* @var \Iterator
protected $items;
* @var \ArrayIterator|null
protected $entries;
* Class constructor.
*
* @param \Iterator $items
public function __construct(\Iterator $items)
$this->items = $items;
$this->prepareNext();
}
* Prepare new entries
* @return void
abstract protected function prepareNext(): void;
* Return the current element
* @return callable|null
public function current(): ?callable
return isset($this->entries) ? $this->entries->current() : null;
* Move forward to next element
public function next(): void
if (!isset($this->entries)) {
// Shouldn't happen if `prepareNext()` works correctly
return; // @codeCoverageIgnore
$this->entries->next();
while (!$this->entries->valid() && $this->items->valid()) {
* Return the key of the current element
* @return string|null
public function key(): ?string
return isset($this->entries) ? (string)$this->entries->key() : null;
* Checks if current position is valid
* @return bool
public function valid(): bool
return isset($this->entries) && $this->entries->valid();
* Rewind the iterator to the first element
public function rewind(): void
$this->items->rewind();
$this->entries = null;
* Returns the inner iterator for the current entry.
* @return \Iterator
public function getInnerIterator(): \Iterator
return $this->items;