summaryrefslogtreecommitdiff
path: root/ext/spl/spl.php
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2005-02-08 20:42:48 +0000
committerMarcus Boerger <helly@php.net>2005-02-08 20:42:48 +0000
commit3fb1c65a41f6d934aa6e3568a5b94055a22d623e (patch)
tree48a1da7745a7289ee9071c40223220a88a06fce1 /ext/spl/spl.php
parent2e8b9c005b480149ed1404fc9c680e881badc9cc (diff)
downloadphp-git-3fb1c65a41f6d934aa6e3568a5b94055a22d623e.tar.gz
- Initial Observer implementation
Diffstat (limited to 'ext/spl/spl.php')
-rwxr-xr-xext/spl/spl.php50
1 files changed, 47 insertions, 3 deletions
diff --git a/ext/spl/spl.php b/ext/spl/spl.php
index c54c22a21a..49309bdf11 100755
--- a/ext/spl/spl.php
+++ b/ext/spl/spl.php
@@ -66,6 +66,9 @@
*
* - class ArrayObject implements IteratorAggregate
* - class ArrayIterator implements Iterator
+ *
+ * As the above suggest an ArrayObject creates an ArrayIterator when it comes to
+ * iteration (e.g. ArrayObject instance used inside foreach).
*
* 5) Counting
*
@@ -88,9 +91,13 @@
* - class OverflowException extends RuntimeException
* - class RangeException extends RuntimeException
* - class UnderflowException extends RuntimeException
- *
- * As the above suggest an ArrayObject creates an ArrayIterator when it comes to
- * iteration (e.g. ArrayObject instance used inside foreach).
+ *
+ * 7) Observer
+ *
+ * SPL suggests a standard way of implementing the observer pattern.
+ *
+ * - interface Observer
+ * - interface Subject
*
* A nice article about SPL can be found
* <a href="http://www.sitepoint.com/article/php5-standard-library/1">here</a>.
@@ -657,4 +664,41 @@ class SimpleXMLIterator extends SimpleXMLElement implements RecursiveIterator
function getChildren();
}
+/** @ingroup SPL
+ * @brief observer of the observer pattern
+ *
+ * For a detailed explanation see Observer pattern in
+ * <em>
+ * Gamma, Helm, Johnson, Vlissides<br />
+ * Design Patterns
+ * </em>
+ */
+interface Observer
+{
+ /** Called from the subject (i.e. when it's value has changed).
+ * @param $subject the callee
+ */
+ function update(Subject $subject);
+}
+
+/** @ingroup SPL
+ * @brief ubject to the observer pattern
+ * @see Observer
+ */
+interface Subject
+{
+ /** @param $observer new observer to attach
+ */
+ function attach(Observer $observer);
+
+ /** @param $observer existing observer to detach
+ * @note a non attached observer shouldn't result in a warning or similar
+ */
+ function detach(Observer $observer);
+
+ /** @param $ignore optional observer that should not be notified
+ */
+ function notify([Observer $ignore = NULL]);
+}
+
?>