Skip to content

Commit dd457c2

Browse files
MacFJAtheseer
authored andcommitted
Add support for @Property / @property-read / @property-write
- Add new parser for property (based on the param parser) - Update docblock parser to handle tags with an hyphen - Update html generator to display dynamic properties Close #77
1 parent 1b457a9 commit dd457c2

File tree

8 files changed

+90
-12
lines changed

8 files changed

+90
-12
lines changed

src/docblock/Factory.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ class Factory {
99
'invalid' => 'TheSeer\\phpDox\\DocBlock\\InvalidParser',
1010
'generic' => 'TheSeer\\phpDox\\DocBlock\\GenericParser',
1111

12-
'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
13-
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
14-
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
15-
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
16-
'throws' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
17-
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',
12+
'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
13+
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
14+
'property-read' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
15+
'property-write' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
16+
'property' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
17+
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
18+
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
19+
'throws' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
20+
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',
1821

1922
'internal' => 'TheSeer\\phpDox\\DocBlock\\InternalParser',
2023
'inheritdoc' => 'TheSeer\\phpDox\\DocBlock\\InheritdocParser'

src/docblock/Parser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function parse($block, array $aliasMap) {
4141
}
4242
$buffer = [];
4343

44-
\preg_match('/^\@([a-zA-Z0-9_]+)(.*)$/', $line, $lineParts);
44+
\preg_match('/^\@([a-zA-Z0-9_-]+)(.*)$/', $line, $lineParts);
4545
$name = ($lineParts[1] ?? '(undefined)');
4646
$payload = (isset($lineParts[2]) ? \trim($lineParts[2]) : '');
4747

templates/html/components.xsl

+50
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,61 @@
287287
</xsl:for-each>
288288
</ul>
289289
</xsl:if>
290+
<xsl:if test="//pdx:docblock/pdx:property">
291+
<h4>magic</h4>
292+
<ul class="members">
293+
<xsl:for-each select="//pdx:docblock/pdx:property">
294+
<xsl:sort select="@variable" />
295+
<xsl:call-template name="magicmemberli" />
296+
</xsl:for-each>
297+
</ul>
298+
</xsl:if>
299+
<xsl:if test="//pdx:docblock/pdx:property-read">
300+
<h4>magic — Read only</h4>
301+
<ul class="members">
302+
<xsl:for-each select="//pdx:docblock/pdx:property-read">
303+
<xsl:sort select="@variable" />
304+
<xsl:call-template name="magicmemberli" />
305+
</xsl:for-each>
306+
</ul>
307+
</xsl:if>
308+
<xsl:if test="//pdx:docblock/pdx:property-write">
309+
<h4>magic — Write only</h4>
310+
<ul class="members">
311+
<xsl:for-each select="//pdx:docblock/pdx:property-write">
312+
<xsl:sort select="@variable" />
313+
<xsl:call-template name="magicmemberli" />
314+
</xsl:for-each>
315+
</ul>
316+
</xsl:if>
290317
</div>
291318
</xsl:template>
292319

293320
<!-- ######################################################################################################### -->
294321

322+
<xsl:template name="magicmemberli">
323+
<li id="{@variable}">
324+
<strong><xsl:value-of select="@variable" /></strong>
325+
<xsl:if test="@type">
326+
327+
<xsl:choose>
328+
<xsl:when test="@type = 'object'">
329+
<xsl:copy-of select="pdxf:link(pdx:type, '', pdx:type/@full)" />
330+
</xsl:when>
331+
<xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
332+
</xsl:choose>
333+
</xsl:if>
334+
<xsl:if test="@description != ''">
335+
<br/>
336+
<span class="indent">
337+
<xsl:value-of select="@description" />
338+
</span>
339+
</xsl:if>
340+
</li>
341+
</xsl:template>
342+
343+
<!-- ######################################################################################################### -->
344+
295345
<xsl:template name="memberli">
296346
<li id="{@name}">
297347
<strong>$<xsl:value-of select="@name" /></strong>

templates/html/synopsis.xsl

+15
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@
7474
</xsl:choose></xsl:if>;
7575
</li>
7676
</xsl:for-each>
77+
<xsl:for-each select="$unit/pdx:docblock/*[self::pdx:property or self::pdx:property-read or self::pdx:property-write]">
78+
<li>
79+
<i>magic<xsl:if test="local-name() = 'property-read'"> (r/o)</xsl:if><xsl:if test="local-name() = 'property-write'"> (w/o)</xsl:if></i>&#160;<xsl:choose>
80+
<xsl:when test="@type = 'object'">
81+
<xsl:value-of select="pdx:type/@name" />
82+
</xsl:when>
83+
<xsl:when test="@type = '{unknown}'">
84+
<xsl:text>object</xsl:text>
85+
</xsl:when>
86+
<xsl:otherwise>
87+
<xsl:value-of select="@type" />
88+
</xsl:otherwise>
89+
</xsl:choose>&#160;<a href="#members"><xsl:value-of select="@variable" /></a>;
90+
</li>
91+
</xsl:for-each>
7792
</ul>
7893
</xsl:if>
7994

tests/Integration/docblock/FactoryTest.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ public static function getInstanceMapDataprovider() {
2525
'invalid' => 'TheSeer\\phpDox\\DocBlock\\InvalidParser',
2626
'generic' => 'TheSeer\\phpDox\\DocBlock\\GenericParser',
2727

28-
'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
29-
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
30-
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
31-
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
32-
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',
28+
'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
29+
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
30+
'property-read' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
31+
'property-write' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
32+
'property' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
33+
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
34+
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
35+
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',
3336

3437
'internal' => 'TheSeer\\phpDox\\DocBlock\\InternalParser'
3538
];

tests/Integration/docblock/ParserTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function docblockSources() {
5656
['param_without_description'],
5757
['param_without_varname'],
5858
['param_without_varname_and_description'],
59+
['property'],
5960
['see'],
6061
['since'],
6162
['throws'],

tests/data/docbock/property

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @property int $state The class state
3+
* @property-read int $pastState The previous class state
4+
* @property-write int $call The number or call
5+
*/

tests/data/docbock/property.xml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<docblock xmlns="http://xml.phpdox.net/src"><description/><property type="int" variable="$state" description="The class state"/><property-read description="The previous class state" type="int" variable="$pastState"/><property-write description="The number or call" type="int" variable="$call"/></docblock>

0 commit comments

Comments
 (0)