@@ -1489,6 +1489,8 @@ private function getFlagsAsArginfoString(): string
1489
1489
* @throws Exception
1490
1490
*/
1491
1491
public function getMethodSynopsisDocument (array $ funcMap , array $ aliasMap ): ?string {
1492
+ $ REFSEC1_SEPERATOR = "\n\n " ;
1493
+
1492
1494
$ doc = new DOMDocument ("1.0 " , "utf-8 " );
1493
1495
$ doc ->formatOutput = true ;
1494
1496
@@ -1526,8 +1528,7 @@ public function getMethodSynopsisDocument(array $funcMap, array $aliasMap): ?str
1526
1528
$ refnamediv ->appendChild ($ refpurpose );
1527
1529
1528
1530
$ refnamediv ->appendChild (new DOMText ("\n " ));
1529
- $ refentry ->appendChild ($ refnamediv );
1530
- $ refentry ->appendChild (new DOMText ("\n\n " ));
1531
+ $ refentry ->append ($ refnamediv , $ REFSEC1_SEPERATOR );
1531
1532
1532
1533
/* Creation of <refsect1 role="description"> */
1533
1534
$ descriptionRefSec = $ doc ->createElement ('refsect1 ' );
@@ -1551,19 +1552,16 @@ public function getMethodSynopsisDocument(array $funcMap, array $aliasMap): ?str
1551
1552
$ descriptionRefSec ->appendChild ($ returnDescriptionPara );
1552
1553
1553
1554
$ descriptionRefSec ->appendChild (new DOMText ("\n " ));
1554
- $ refentry ->appendChild ($ descriptionRefSec );
1555
- $ refentry ->appendChild (new DOMText ("\n\n " ));
1555
+ $ refentry ->append ($ descriptionRefSec , $ REFSEC1_SEPERATOR );
1556
1556
1557
1557
/* Creation of <refsect1 role="parameters"> */
1558
1558
$ parametersRefSec = $ this ->getParameterSection ($ doc );
1559
- $ refentry ->appendChild ($ parametersRefSec );
1560
- $ refentry ->appendChild (new DOMText ("\n\n " ));
1559
+ $ refentry ->append ($ parametersRefSec , $ REFSEC1_SEPERATOR );
1561
1560
1562
1561
/* Creation of <refsect1 role="returnvalues"> */
1563
1562
if (!$ this ->name ->isConstructor () && !$ this ->name ->isDestructor ()) {
1564
1563
$ returnRefSec = $ this ->getReturnValueSection ($ doc );
1565
- $ refentry ->appendChild ($ returnRefSec );
1566
- $ refentry ->appendChild (new DOMText ("\n\n " ));
1564
+ $ refentry ->append ($ returnRefSec , $ REFSEC1_SEPERATOR );
1567
1565
}
1568
1566
1569
1567
/* Creation of <refsect1 role="errors"> */
@@ -1578,15 +1576,15 @@ public function getMethodSynopsisDocument(array $funcMap, array $aliasMap): ?str
1578
1576
$ errorsRefSec ->appendChild ($ errorsDescriptionPara );
1579
1577
$ errorsRefSec ->appendChild (new DOMText ("\n " ));
1580
1578
1581
- $ refentry ->appendChild ($ errorsRefSec );
1582
- $ refentry ->appendChild (new DOMText ("\n\n " ));
1579
+ $ refentry ->append ($ errorsRefSec , $ REFSEC1_SEPERATOR );
1583
1580
1584
1581
/* Creation of <refsect1 role="changelog"> */
1585
1582
$ changelogRefSec = $ this ->getChangelogSection ($ doc );
1586
- $ refentry ->appendChild ($ changelogRefSec );
1587
- $ refentry ->appendChild (new DOMText ("\n\n " ));
1583
+ $ refentry ->append ($ changelogRefSec , $ REFSEC1_SEPERATOR );
1588
1584
1589
1585
// TODO Examples, and Notes sections
1586
+ $ exampleRefSec = $ this ->getExampleSection ($ doc );
1587
+ $ refentry ->append ($ exampleRefSec , $ REFSEC1_SEPERATOR );
1590
1588
1591
1589
/* Creation of <refsect1 role="seealso"> */
1592
1590
$ seeAlsoRefSec = $ doc ->createElement ('refsect1 ' );
@@ -1822,6 +1820,65 @@ private function getChangelogSection(DOMDocument $doc): DOMElement {
1822
1820
return $ refSec ;
1823
1821
}
1824
1822
1823
+ private function getExampleSection(DOMDocument $ doc ): DOMElement {
1824
+ $ refSec = $ doc ->createElement ('refsect1 ' );
1825
+ $ refSec ->setAttribute ('role ' , 'examples ' );
1826
+ $ refTitle = $ doc ->createEntityReference ('reftitle.examples ' );
1827
+ $ refSec ->append ("\n " , $ refTitle );
1828
+
1829
+ $ example = $ doc ->createElement ('example ' );
1830
+ $ example ->setAttribute ('xml:id ' , 'func-or-method-name.example.basic ' );
1831
+
1832
+ $ title = $ doc ->createElement ('title ' );
1833
+ $ fn = $ doc ->createElement ($ this ->isMethod () ? 'methodname ' : 'function ' );
1834
+ $ fn ->append ($ this ->name ->__toString ());
1835
+ $ title ->append ($ fn , ' example ' );
1836
+
1837
+ $ example ->append ("\n " , $ title );
1838
+
1839
+ $ para = $ doc ->createElement ('para ' );
1840
+ $ para ->append ("\n " , "Description. " , "\n " );
1841
+ $ example ->append ("\n " , $ para );
1842
+
1843
+ $ prog = $ doc ->createElement ('programlisting ' );
1844
+ $ prog ->setAttribute ('role ' , 'php ' );
1845
+ $ code = new DOMCdataSection(
1846
+ <<<CODE_EXAMPLE
1847
+
1848
+ <?php
1849
+ echo "Code example";
1850
+ ?>
1851
+
1852
+ CODE_EXAMPLE
1853
+ );
1854
+ $prog->append("\n");
1855
+ $prog->appendChild($code);
1856
+ $prog->append("\n ");
1857
+
1858
+ $example->append("\n ", $prog);
1859
+ $example->append("\n ", $doc->createEntityReference('example.outputs'));
1860
+
1861
+ $output = new DOMCdataSection(
1862
+ <<<OUPUT_EXAMPLE
1863
+
1864
+ Code example
1865
+
1866
+ OUPUT_EXAMPLE
1867
+ );
1868
+ $screen = $doc->createElement('screen');
1869
+ $screen->append("\n");
1870
+ $screen->appendChild($output);
1871
+ $screen->append("\n ");
1872
+
1873
+ $example->append("\n ", $screen);
1874
+ $example->append("\n ");
1875
+
1876
+ $refSec->append("\n ", $example);
1877
+
1878
+ $refSec->appendChild(new DOMText("\n "));
1879
+ return $refSec;
1880
+ }
1881
+
1825
1882
/**
1826
1883
* @param array<string, FuncInfo> $funcMap
1827
1884
* @param array<string, FuncInfo> $aliasMap
0 commit comments