mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-09 16:36:37 +02:00
execute read-the-docs.sh
This commit is contained in:
69
Behavioral/Iterator/index.rst
Normal file
69
Behavioral/Iterator/index.rst
Normal file
@@ -0,0 +1,69 @@
|
||||
Iterator
|
||||
========
|
||||
|
||||
Purpose
|
||||
-------
|
||||
|
||||
To make an object iterable and to make it appear like a collection of
|
||||
objects.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
- to process a file line by line by just running over all lines (which
|
||||
have an object representation) for a file (which of course is an
|
||||
object, too)
|
||||
|
||||
Note
|
||||
----
|
||||
|
||||
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
|
||||
|
||||
UML Diagram
|
||||
-----------
|
||||
|
||||
.. image:: uml/uml.png
|
||||
:alt: Alt Iterator UML Diagram
|
||||
:align: center
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
You can also find these code on `GitHub`_
|
||||
|
||||
BookList.php
|
||||
|
||||
.. literalinclude:: BookList.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
BookListReverseIterator.php
|
||||
|
||||
.. literalinclude:: BookListReverseIterator.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
BookListIterator.php
|
||||
|
||||
.. literalinclude:: BookListIterator.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
Book.php
|
||||
|
||||
.. literalinclude:: Book.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
Test
|
||||
----
|
||||
|
||||
Tests/IteratorTest.php
|
||||
|
||||
.. literalinclude:: Tests/IteratorTest.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Iterator
|
Reference in New Issue
Block a user