Behavioral/Iterator/README.rst
Iterator__To make an object iterable and to make it appear like a collection of objects.
Standard PHP Library (SPL) defines an interface Iterator which is best
suited for this! Often you would want to implement the Countable
interface too, to allow count($object) on your iterable object
.. image:: uml/uml.png :alt: Alt Iterator UML Diagram :align: center
You can also find this code on GitHub_
Book.php
.. literalinclude:: Book.php :language: php :linenos:
BookList.php
.. literalinclude:: BookList.php :language: php :linenos:
Tests/IteratorTest.php
.. literalinclude:: Tests/IteratorTest.php :language: php :linenos:
.. _GitHub: https://github.com/DesignPatternsPHP/DesignPatternsPHP/tree/main/Behavioral/Iterator
.. __: http://en.wikipedia.org/wiki/Iterator_pattern