From e168effb8a63ed96ae6b40d8ece8be5a5c0e22f5 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 2 May 2023 15:20:51 +1200 Subject: [PATCH] ENH Display protected methods/properties --- conf/themes/silverstripe/class.twig | 47 ++++++++++++++++++++++-- src/Parser/Filter/SilverStripeFilter.php | 9 ++--- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/conf/themes/silverstripe/class.twig b/conf/themes/silverstripe/class.twig index 20aa18a..47c69b4 100644 --- a/conf/themes/silverstripe/class.twig +++ b/conf/themes/silverstripe/class.twig @@ -1,5 +1,5 @@ {% extends "default/class.twig" %} -{% from "macros.twig" import render_classes, property_link, hint_link, deprecated, deprecations, internals, todos %} +{% from "macros.twig" import render_classes, property_link, method_link, hint_link, deprecated, deprecations, internals, todos %} {# This has to be included so that we can add config after constants #} {% block page_content %} @@ -72,7 +72,7 @@ {% endblock %} -{# This has to be included so that we can exclude config from the properties section #} +{# This has to be included so that we can exclude config from the properties section, and to rearrange some display items #} {% block properties %} {% for property in properties %} @@ -81,10 +81,12 @@ {# END CUSTOMISATION #} + {# BEGIN CUSTOMISATION - move type hint into its own column to match config #} + + {# END CUSTOMISATION #}
- {% if property.isStatic() %}static{% endif %} + {# BEGIN CUSTOMISATION - add public, and reorder so that static is after visibility #} + {% if property.isPublic() %}public{% endif %} {% if property.isProtected() %}protected{% endif %} {% if property.isPrivate() %}private{% endif %} - {{ hint_link(property.hint) }} + {% if property.isStatic() %}static{% endif %} + {# END CUSTOMISATION #} {% if property.isInternal() %}{% trans 'internal' %}{% endif %} {% if property.isDeprecated() %}{% trans 'deprecated' %}{% endif %} {% if property.isReadOnly() %}{% trans 'read-only' %}{% endif %} @@ -95,6 +97,9 @@
{% endif %}
{{ hint_link(property.hint) }} ${{ property.name|raw }} {{ property.shortdesc|desc(class)|md_to_html }} @@ -110,6 +115,40 @@
{% endblock %} +{# This has to be included to include visibility and rearrange things slightly #} +{% block methods %} +
+ {% for method in methods %} +
+ {# BEGIN CUSTOMISATION - add visibility and move type hint into its own column #} +
+ {% if method.isPublic() %}public{% endif %} + {% if method.isProtected() %}protected{% endif %} + {% if method.isPrivate() %}private{% endif %} + {% if method.static %}static {% endif %} +
+
+ {{ hint_link(method.hint) }} +
+ {# END CUSTOMISATION #} +
+ {{ method.name|raw }}{{ block('method_parameters_signature') }} + {% if not method.shortdesc %} +

{% trans 'No description' %}

+ {% else %} +

{{ method.shortdesc|desc(class)|md_to_html }}

+ {%- endif %} +
+
+ {%- if method.class is not same as(class) -%} + {{ 'from %s'|trans|format(method_link(method, false, true))|raw }} + {%- endif -%} +
+
+ {% endfor %} +
+{% endblock %} + {# BEGIN CUSTOMISATION - completely new block #} {% block configs %} diff --git a/src/Parser/Filter/SilverStripeFilter.php b/src/Parser/Filter/SilverStripeFilter.php index 1defb0f..f7bcea1 100644 --- a/src/Parser/Filter/SilverStripeFilter.php +++ b/src/Parser/Filter/SilverStripeFilter.php @@ -2,12 +2,12 @@ namespace SilverStripe\ApiDocs\Parser\Filter; -use Doctum\Parser\Filter\PublicFilter; +use Doctum\Parser\Filter\DefaultFilter; use Doctum\Reflection\ClassReflection; use Doctum\Reflection\MethodReflection; use Doctum\Reflection\PropertyReflection; -class SilverStripeFilter extends PublicFilter +class SilverStripeFilter extends DefaultFilter { public function acceptClass(ClassReflection $class) { @@ -21,8 +21,7 @@ public function acceptMethod(MethodReflection $method) public function acceptProperty(PropertyReflection $property) { - // if there's a config tag, then we want to document it - return !$property->getTags('internal') && - ($property->getTags('config') || parent::acceptProperty($property)); + // Explicitly allow private static properties + return !$property->getTags('internal') && ($property->isStatic() || parent::acceptProperty($property)); } }