From 6078eb77f242907d44639cfdd29b9da139e7b5fb Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 12 Sep 2020 16:33:54 +0200 Subject: [PATCH] Support variadic parameters So far, PhD does not support variadic parameters. Instead the manual follows the convention to use `...` as parameter name, which is then rendered as `$...` in the docs. However, as of PHP 5.6.0 variadic parameters are supported using the syntax `...$args`; therefore, we are going to support this notation for PhD. While DocBook supports a `` element, this cannot be used in combination with named parameters. Therefore, we use the `role` attribute of the `` element to declare variadic parameters. Since the `role` attribute is already used to designate reference parameters, we support the following values now: `"reference"`, `"variadic"` and `"reference variadic"`; additional whitespace as well as swapping the order of the words is supported. --- phpdotnet/phd/Package/Generic/XHTML.php | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 798175bf..7ab6f968 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -997,10 +997,19 @@ public function format_methodparam_parameter($open, $name, $attrs, $props) return ''; } if ($open) { + $class = 'parameter'; + $et = $ellipsis = ''; if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { - return ' &$'; + $role = $attrs[Reader::XMLNS_DOCBOOK]["role"]; + if (preg_match('/\breference\b/', $role)) { + $class .= ' reference'; + $et = '&'; + } + if (preg_match('/\bvariadic\b/', $role)) { + $ellipsis = '...'; + } } - return ' $'; + return " {$et}{$ellipsis}$"; } return ""; } @@ -1017,10 +1026,19 @@ public function format_parameter($open, $name, $attrs, $props) return ''; } if ($open) { + $class = 'parameter'; + $et = $ellipsis = ''; if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { - return '&'; + $role = $attrs[Reader::XMLNS_DOCBOOK]["role"]; + if (preg_match('/\breference\b/', $role)) { + $class .= ' reference'; + $et = '&'; + } + if (preg_match('/\bvariadic\b/', $role)) { + $ellipsis = '...'; + } } - return ''; + return " {$et}{$ellipsis}"; } return ""; }