Skip to content

Instantly share code, notes, and snippets.

@LawnGnome
Created June 11, 2014 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LawnGnome/ade9fffb66b77d369e49 to your computer and use it in GitHub Desktop.
Save LawnGnome/ade9fffb66b77d369e49 to your computer and use it in GitHub Desktop.
<phpdoc:inherited>
Index: doc-base/configure.php
===================================================================
--- doc-base/configure.php (revision 333740)
+++ doc-base/configure.php (working copy)
@@ -677,6 +677,66 @@
}
echo "done.\n";
+echo "Handling phpdoc:inherited elements... ";
+
+function class_to_id($class) {
+ return 'class.'.strtolower(str_replace(array('\\', '_'), '-', $class));
+}
+
+function create_inherited_nodes($dom, $xp, $class) {
+ if ($parent = find_parent_class($dom, $xp, $class)) {
+ $id = class_to_id($parent);
+
+ $xi = $dom->createElementNS('http://www.w3.org/2001/XInclude', 'xi:include');
+ $xi->setAttribute('xpointer', "xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$id')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])");
+
+ if ($nodes = create_inherited_nodes($dom, $xp, $parent)) {
+ array_unshift($nodes, $xi);
+ return $nodes;
+ }
+
+ return array($xi);
+ }
+}
+
+function find_parent_class($dom, $xp, $class) {
+ $id = class_to_id($class);
+ if ($node = $dom->getElementById($id)) {
+ $classname = $xp->query('.//db:modifier[text()="extends"]/../db:classname', $node);
+ if ($classname->length == 1) {
+ return trim($classname->item(0)->textContent);
+ }
+ }
+}
+
+// Process phpdoc:inherited elements.
+$xp = new DOMXPath($dom);
+$xp->registerNamespace('db', 'http://docbook.org/ns/docbook');
+$xp->registerNamespace('phpdoc', 'http://php.net/ns/phpdoc');
+foreach ($xp->query('//phpdoc:inherited') as $inherited) {
+ $parent = $inherited->parentNode;
+
+ // Attempt to find the parent classes and replace the inherited node with an
+ // appropriate xinclude.
+ $classname = $xp->query('ancestor::phpdoc:classref[1]|ancestor::phpdoc:exceptionref[1]//db:classsynopsis/db:ooclass/db:classname', $inherited);
+ if ($classname->length == 1) {
+ $class = trim($classname->item(0)->textContent);
+ if ($nodes = create_inherited_nodes($dom, $xp, $class)) {
+ foreach ($nodes as $node) {
+ $parent->insertBefore($node, $inherited);
+ }
+ } else {
+ echo "No inherited functions found for $class: this is probably an error\n";
+ }
+ } else {
+ echo "Cannot find class name\n";
+ }
+
+ // This always has to be removed anyway.
+ $parent->removeChild($inherited);
+}
+
+echo "done.\n";
echo "Validating {$ac["INPUT_FILENAME"]}... ";
flush();
Index: en/reference/spl/globiterator.xml
===================================================================
--- en/reference/spl/globiterator.xml (revision 333740)
+++ en/reference/spl/globiterator.xml (working copy)
@@ -50,7 +50,7 @@
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.globiterator')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
<classsynopsisinfo role="comment">&InheritedMethods;</classsynopsisinfo>
- <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.filesystemiterator')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
+ <phpdoc:inherited />
</classsynopsis>
<!-- }}} -->
Index: en/reference/spl/overflowexception.xml
===================================================================
--- en/reference/spl/overflowexception.xml (revision 333740)
+++ en/reference/spl/overflowexception.xml (working copy)
@@ -48,7 +48,7 @@
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.overflowexception')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
-->
<classsynopsisinfo role="comment">&InheritedMethods;</classsynopsisinfo>
- <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.exception')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
+ <phpdoc:inherited />
</classsynopsis>
<!-- }}} -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment