Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document compareDocumentPosition & related constants #4081

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion reference/dom/domnode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@
<classname>DOMNode</classname>
</ooclass>

<classsynopsisinfo role="comment">&Constants;</classsynopsisinfo>
<fieldsynopsis>
<modifier>public</modifier>
<modifier>const</modifier>
<type>int</type>
<varname linkend="domnode.constants.document-position-disconnected">DOMNode::DOCUMENT_POSITION_DISCONNECTED</varname>
<initializer>1</initializer>
</fieldsynopsis>
<fieldsynopsis>
<modifier>public</modifier>
<modifier>const</modifier>
<type>int</type>
<varname linkend="domnode.constants.document-position-preceding">DOMNode::DOCUMENT_POSITION_PRECEDING</varname>
<initializer>2</initializer>
</fieldsynopsis>
<fieldsynopsis>
<modifier>public</modifier>
<modifier>const</modifier>
<type>int</type>
<varname linkend="domnode.constants.document-position-following">DOMNode::DOCUMENT_POSITION_FOLLOWING</varname>
<initializer>4</initializer>
</fieldsynopsis>
<fieldsynopsis>
<modifier>public</modifier>
<modifier>const</modifier>
<type>int</type>
<varname linkend="domnode.constants.document-position-contains">DOMNode::DOCUMENT_POSITION_CONTAINS</varname>
<initializer>8</initializer>
</fieldsynopsis>
<fieldsynopsis>
<modifier>public</modifier>
<modifier>const</modifier>
<type>int</type>
<varname linkend="domnode.constants.document-position-contained-by">DOMNode::DOCUMENT_POSITION_CONTAINED_BY</varname>
<initializer>16</initializer>
</fieldsynopsis>
<fieldsynopsis>
<modifier>public</modifier>
<modifier>const</modifier>
<type>int</type>
<varname linkend="domnode.constants.document-position-implementation-specific">DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC</varname>
<initializer>32</initializer>
</fieldsynopsis>

<classsynopsisinfo role="comment">&Properties;</classsynopsisinfo>
<fieldsynopsis>
<modifier>public</modifier>
Expand Down Expand Up @@ -139,7 +183,75 @@
<!-- }}} -->

</section>


<section xml:id="domnode.constants">
&reftitle.constants;
<variablelist>
<varlistentry xml:id="domnode.constants.document-position-disconnected">
<term>
<constant>DOMNode::DOCUMENT_POSITION_DISCONNECTED</constant>
</term>
<listitem>
<simpara>
Set when the other node and reference node are not in the same tree.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="domnode.constants.document-position-preceding">
<term>
<constant>DOMNode::DOCUMENT_POSITION_PRECEDING</constant>
</term>
<listitem>
<simpara>
Set when the other node precedes the reference node.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="domnode.constants.document-position-following">
<term>
<constant>DOMNode::DOCUMENT_POSITION_FOLLOWING</constant>
</term>
<listitem>
<simpara>
Set when the other node follows the reference node.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="domnode.constants.document-position-contains">
<term>
<constant>DOMNode::DOCUMENT_POSITION_CONTAINS</constant>
</term>
<listitem>
<simpara>
Set when the other node is an ancestor of the reference node.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="domnode.constants.document-position-contained-by">
<term>
<constant>DOMNode::DOCUMENT_POSITION_CONTAINED_BY</constant>
</term>
<listitem>
<simpara>
Set when the other node is a descendant of the reference node.
</simpara>
</listitem>
</varlistentry>
<varlistentry xml:id="domnode.constants.document-position-implementation-specific">
<term>
<constant>DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC</constant>
</term>
<listitem>
<simpara>
Set when the result depends on implementation-specific behaviour and
may not be portable.
This may happen with disconnected nodes or with attribute nodes.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</section>

<!-- {{{ DOMNode properties -->
<section xml:id="domnode.props">
&reftitle.properties;
Expand Down
96 changes: 96 additions & 0 deletions reference/dom/domnode/compareDocumentPosition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="domnode.comparedocumentposition" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>DOMNode::compareDocumentPosition</refname>
<refpurpose>Compares the position of two nodes</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="DOMNode">
<modifier>public</modifier> <type>int</type><methodname>DOMNode::compareDocumentPosition</methodname>
<methodparam><type>DOMNode</type><parameter>other</parameter></methodparam>
</methodsynopsis>
<simpara>
Compares the position of the other node relative to this node.
</simpara>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>other</parameter></term>
<listitem>
<para>
The node for which the position should be compared for, relative to this node.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
A bitmask of the <link linkend="domnode.constants">DOMNode::DOCUMENT_POSITION_*</link>
nielsdos marked this conversation as resolved.
Show resolved Hide resolved
constants.
</simpara>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title><methodname>DOMNode::compareDocumentPosition</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
$xml = <<<XML
<root>
<child1/>
<child2/>
</root>
XML;

$dom = new DOMDocument();
$dom->loadXML($xml);

$root = $dom->documentElement;
$child1 = $root->firstElementChild;
$child2 = $child1->nextElementSibling;

var_dump($root->compareDocumentPosition($child1));
var_dump($child2->compareDocumentPosition($child1));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(20) // This is DOMNode::DOCUMENT_POSITION_CONTAINED_BY | DOMNode::DOCUMENT_POSITION_FOLLOWING
int(2) // This is DOMNode::DOCUMENT_POSITION_PRECEDING
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- 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
-->
2 changes: 1 addition & 1 deletion reference/dom/versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<function name="domnode::c14n" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
<function name="domnode::c14nfile" from="PHP 5 &gt;= 5.2.0, PHP 7, PHP 8"/>
<function name="domnode::clonenode" from="PHP 5, PHP 7, PHP 8"/>
<function name="domnode::comparedocumentposition" from="PHP 5, PHP 7"/>
<function name="domnode::comparedocumentposition" from="PHP 8 &gt;= 8.4.0"/>
<function name="domnode::contains" from="PHP 8 &gt;= 8.3.0"/>
<function name="domnode::getfeature" from="PHP 5, PHP 7"/>
<function name="domnode::getlineno" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
Expand Down