cvs: phpdoc /en/reference/spl seekableiterator.xml /en/reference/spl/seekableiterator seek.xml
| From: | Peter Cowburn | Date: | Sun, 14 Jun 2009 19:52:52 +0000 |
| Subject: | cvs: phpdoc /en/reference/spl seekableiterator.xml /en/reference/spl/seekableiterator seek.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4146@lists.php.net to get a copy of this message | ||
salathe Sun Jun 14 19:52:52 2009 UTC
Modified files:
/phpdoc/en/reference/spl/seekableiterator seek.xml
/phpdoc/en/reference/spl seekableiterator.xml
Log:
Updated SeekableIterator
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/spl/seekableiterator/seek.xml?r1=1.1&r2=1.2&diff_format=u
Index: phpdoc/en/reference/spl/seekableiterator/seek.xml
diff -u phpdoc/en/reference/spl/seekableiterator/seek.xml:1.1
phpdoc/en/reference/spl/seekableiterator/seek.xml:1.2
--- phpdoc/en/reference/spl/seekableiterator/seek.xml:1.1 Mon Mar 23 23:45:34 2009
+++ phpdoc/en/reference/spl/seekableiterator/seek.xml Sun Jun 14 19:52:52 2009
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- $Revision: 1.1 $ -->
+<!-- $Revision: 1.2 $ -->
<refentry xml:id="seekableiterator.seek" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
@@ -11,14 +11,12 @@
&reftitle.description;
<methodsynopsis>
<modifier>abstract</modifier> <modifier>public</modifier>
<type>void</type><methodname>SeekableIterator::seek</methodname>
-
<methodparam><type>string</type><parameter>position</parameter></methodparam>
+
<methodparam><type>int</type><parameter>position</parameter></methodparam>
</methodsynopsis>
<para>
Seeks to a given position in the iterator.
</para>
- &warn.undocumented.func;
-
</refsect1>
<refsect1 role="parameters">
@@ -44,6 +42,53 @@
</para>
</refsect1>
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <para>
+ Implementations should throw an <classname>OutOfBoundsException</classname>
+ if the <parameter>position</parameter> is not seekable.
+ </para>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <para>
+ <example>
+ <title><methodname>SeekableIterator::seek</methodname> example</title>
+ <para>
+ Seek to the item at position 3 in the iterator
+ (<classname>ArrayIterator</classname> implements
<classname>SeekableIterator</classname>).
+ </para>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$array = array("apple", "banana", "cherry", "damson",
"elderberry");
+$iterator = new ArrayIterator($array);
+$iterator->seek(3);
+echo $iterator->current();
+?>
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+damson
+]]>
+ </screen>
+ </example>
+ </para>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <para>
+ <simplelist>
+ <member><classname>SeekableIterator</classname></member>
+ <member><classname>Iterator</classname></member>
+ </simplelist>
+ </para>
+ </refsect1>
+
</refentry>
<!-- Keep this comment at the end of the file
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/spl/seekableiterator.xml?r1=1.2&r2=1.3&diff_format=u
Index: phpdoc/en/reference/spl/seekableiterator.xml
diff -u phpdoc/en/reference/spl/seekableiterator.xml:1.2
phpdoc/en/reference/spl/seekableiterator.xml:1.3
--- phpdoc/en/reference/spl/seekableiterator.xml:1.2 Fri Apr 24 10:33:28 2009
+++ phpdoc/en/reference/spl/seekableiterator.xml Sun Jun 14 19:52:52 2009
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
<phpdoc:classref xml:id="class.seekableiterator" xmlns:phpdoc="http://php.net/ns/phpdoc" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
@@ -39,11 +39,101 @@
<classsynopsisinfo role="comment">Methods</classsynopsisinfo>
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook)
xpointer(id('class.seekableiterator')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])"
/>
+
+ <classsynopsisinfo role="comment">Inherited methods</classsynopsisinfo>
+ <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook)
xpointer(id('class.iterator')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])"
/>
</classsynopsis>
<!-- }}} -->
</section>
+ <section xml:id="seekableiterator.examples">
+ <example xml:id="seekableiterator.examples.basic"><!-- {{{ -->
+ <title>Basic usage</title>
+ <para>
+ This example demonstrates creating a custom
<classname>SeekableIterator</classname>,
+ seeking to a position and handling an invalid position.
+ </para>
+ <programlisting role="php">
+<![CDATA[
+<?php
+class MySeekableIterator implements SeekableIterator {
+
+ private $position = 0;
+
+ private $array = array(
+ "first element",
+ "second element",
+ "third element",
+ "fourth element"
+ );
+
+ public function seek($position) {
+ $this->position = $position;
+
+ if (!$this->valid()) {
+ throw new OutOfBoundsException("invalid seek position ($position)");
+ }
+ }
+
+ /* Methods required for Iterator interface */
+
+ public function __construct() {
+ $this->position = 0;
+ }
+
+ public function rewind() {
+ $this->position = 0;
+ }
+
+ public function current() {
+ return $this->array[$this->position];
+ }
+
+ public function key() {
+ return $this->position;
+ }
+
+ public function next() {
+ ++$this->position;
+ }
+
+ public function valid() {
+ return isset($this->array[$this->position]);
+ }
+}
+
+try {
+
+ $it = new MySeekableIterator;
+ echo $it->current(), "\n";
+
+ $it->seek(2);
+ echo $it->current(), "\n";
+
+ $it->seek(1);
+ echo $it->current(), "\n";
+
+ $it->seek(10);
+
+} catch (OutOfBoundsException $e) {
+ echo $e->getMessage();
+}
+?>
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+first element
+third element
+second element
+invalid seek position (10)
+]]>
+ </screen>
+ </example><!-- }}} -->
+ </section>
+
</partintro>
&reference.spl.entities.seekableiterator;