Add interface PlIteraface and the corresponding abstract class
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 28 Sep 2010 09:04:14 +0000 (11:04 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 28 Sep 2010 09:15:54 +0000 (11:15 +0200)
PlAbstractIterable.

PlIterable aims at providing a common interface for the objects that can
produce a PlIterator. It extends PHP's IteratorAggregate that provides an
interface for producing a PHP's iterator.

PlAbstractIterable provides a default implementation for
IteratorAggregate::getIterator.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/plabstractiterable.php [new file with mode: 0644]
classes/pliterable.php [new file with mode: 0644]

diff --git a/classes/plabstractiterable.php b/classes/plabstractiterable.php
new file mode 100644 (file)
index 0000000..839f647
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+/** See PlIterable for informations about this class.
+ */
+abstract class PlAbstractIterable implements PlIterable
+{
+    public function getIterator()
+    {
+        return PlIteratorUtils::foreachIterator($this->iterate());
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
diff --git a/classes/pliterable.php b/classes/pliterable.php
new file mode 100644 (file)
index 0000000..2172ec9
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+/** An object that produce an iterator.
+ *
+ * This interface exposes both PlIterator and PHP's iterator versions. An
+ * abstract class PlAbstractIterable implements the PHP's iterator version
+ * from the PlIterator one.
+ */
+interface PlIterable extends IteratorAggregate
+{
+    /** Return a PlIterator over the object.
+     */
+    public function iterate();
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>