php-doc-en/reference/spl/seekableiterator.xml
Máté Kocsis c80e398bcb
Generate ext/spl class synopses from stubs - part 3 (#1224)
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2021-12-21 15:31:10 +01:00

162 lines
3.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<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">
<title>The SeekableIterator interface</title>
<titleabbrev>SeekableIterator</titleabbrev>
<partintro>
<!-- {{{ SeekableIterator intro -->
<section xml:id="seekableiterator.intro">
&reftitle.intro;
<para>
The Seekable iterator.
</para>
</section>
<!-- }}} -->
<section xml:id="seekableiterator.synopsis">
&reftitle.interfacesynopsis;
<!-- {{{ Synopsis -->
<classsynopsis>
<ooclass>
<classname>SeekableIterator</classname>
</ooclass>
<classsynopsisinfo>
<oointerface>
<interfacename>SeekableIterator</interfacename>
</oointerface>
<ooclass>
<modifier>extends</modifier>
<classname>Iterator</classname>
</ooclass>
</classsynopsisinfo>
<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[not(@role='procedural')])">
<xi:fallback/>
</xi:include>
<classsynopsisinfo role="comment">&InheritedMethods;</classsynopsisinfo>
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.iterator')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])">
<xi:fallback/>
</xi:include>
</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;
private $array = array(
"first element",
"second element",
"third element",
"fourth element"
);
/* Method required for SeekableIterator interface */
public function seek($position) {
if (!isset($this->array[$position])) {
throw new OutOfBoundsException("invalid seek position ($position)");
}
$this->position = $position;
}
/* Methods required for Iterator interface */
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;
</phpdoc:classref>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->