Skip to content

Commit 53836ce

Browse files
authored
Enhance PHP API Ref (#2584)
* .phpdoc/template/components/tags.html.twig: Handle @Used-By * .phpdoc/template/components/properties.html.twig: Get duplicates closer to each others. * .phpdoc/template/class.html.twig: Deduplicates properties * .phpdoc/template: Indicate interface or abstract * .phpdoc/template/trait.html.twig: Add missing template * .phpdoc/template/: Redo external links to GitHub using JS
1 parent e754278 commit 53836ce

File tree

11 files changed

+154
-19
lines changed

11 files changed

+154
-19
lines changed

tools/php_api_ref/.phpdoc/template/base.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{{ parent() }}
77

88
<script>
9+
window.symfonyVersion = '{{ symfony_version }}';
910
window.addEventListener('keyup', (event) => {
1011
if (event.key === '/') {
1112
event.stopImmediatePropagation();

tools/php_api_ref/.phpdoc/template/class.html.twig

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
{% block content %}
1010
{% include 'components/breadcrumbs.html.twig' %}
11-
{% include 'components/class-title.html.twig' with { symfony_version: symfony_version } %}
12-
{% include('components/element-header.html.twig') %}
11+
{% include 'components/class-title.html.twig' %}
12+
{% include 'components/element-header.html.twig' %}
1313
{% include 'components/constants.html.twig' %}
1414
{% include 'components/properties.html.twig' %}
1515
{% include 'components/methods.html.twig' %}
@@ -52,12 +52,16 @@
5252
</a>
5353
<nav class="md-nav">
5454
<ul class="md-nav__list">
55+
{% set treated_properties = [] %}
5556
{% for property in properties|sortByVisibility %}
56-
<li class="md-nav__item level-2">
57-
<a href="{{ link(property) }}" title="{{ property.name }}" class="md-nav__link">
58-
{{ property.name }}
59-
</a>
60-
</li>
57+
{% if property.__toString() not in treated_properties %}
58+
<li class="md-nav__item level-2">
59+
<a href="{{ link(property) }}" title="{{ property.name }}" class="md-nav__link">
60+
{{ property.name }}
61+
</a>
62+
</li>
63+
{% set treated_properties = treated_properties|merge([property.__toString()]) %}
64+
{% endif %}
6165
{% endfor %}
6266
</ul>
6367
</nav>

tools/php_api_ref/.phpdoc/template/components/class-title.html.twig

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
add_edition: true,
99
} %}
1010
{% block subheader %}
11+
{% if node.isAbstract %}
12+
<div class="content-header__subheader">Abstract</div>
13+
{% endif %}
14+
1115
{% if node.parent %}
1216
<div class="content-header__subheader">
13-
{% if node.parent.__toString starts with '\\Symfony\\' %}
14-
Extends
15-
<a href="{{ 'https://github.com/symfony/symfony/blob/' ~ symfony_version ~ '/src' ~ node.parent|replace({'\\': '/'}) ~ '.php' }}" class="external">
16-
<abbr title="{{ node.parent }}">{{ node.parent.name }}</abbr>
17-
</a>
18-
{% else %}
19-
Extends {{ node.parent|route('class:short') }}
20-
{% endif %}
17+
Extends {{ node.parent|route('class:short') }}
2118
</div>
2219
{% endif %}
2320

tools/php_api_ref/.phpdoc/template/components/interface-title.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
add_edition: true,
99
} %}
1010
{% block subheader %}
11+
<div class="content-header__subheader">Interface</div>
12+
1113
{% if node.parent is not empty %}
1214
<div class="content-header__subheader">
1315
Extends
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{% set properties = properties(node)|sortByVisibility %}
2+
{% set explorable_properties = properties(node)|sortByVisibility %}
3+
{% set treated_properties = [] %}
24

35
{% if properties is not empty %}
46
<h2 id="properties">
@@ -7,7 +9,14 @@
79
</h2>
810

911
{% for property in properties %}
10-
{% include 'components/property.html.twig' %}
12+
{% if property.__toString() not in treated_properties %}
13+
{% for explored_property in explorable_properties %}
14+
{% if explored_property.__toString() == property.__toString() %}
15+
{% include 'components/property.html.twig' with {'property': explored_property} %}
16+
{% endif %}
17+
{% endfor %}
18+
{% set treated_properties = treated_properties|merge([property.__toString()]) %}
19+
{% endif %}
1120
{% endfor %}
1221
</section>
1322
{% endif %}

tools/php_api_ref/.phpdoc/template/components/tags.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% set tags = node.tags|filter((v,k) => k not in excluded_tags and not (k starts with 'phpstan-')) %}
44
{% set has_tags = false %}
55
{% for name,seriesOfTag in tags %}
6-
{% if name in ['see', 'uses'] %}
6+
{% if name in ['see', 'uses', 'used-by'] %}
77
{% set seriesOfTag = seriesOfTag|filter(tag => '<a ' in tag.reference|route('class:short')) %}
88
{% endif %}
99
{% if seriesOfTag|length > 0 %}
@@ -19,7 +19,7 @@
1919
</h5>
2020
<dl class="phpdocumentor-tag-list">
2121
{% for name,seriesOfTag in tags %}
22-
{% if name in ['see', 'uses'] %}
22+
{% if name in ['see', 'uses', 'used-by'] %}
2323
{% set seriesOfTag = seriesOfTag|filter(tag => '<a ' in tag.reference|route('class:short')) %}
2424
{% endif %}
2525
{% for tag in seriesOfTag %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{% set breadcrumbs = usesNamespaces ? breadcrumbs(node) : packages(node) %}
2+
{% set fqcn = breadcrumbs|map(breadcrumb => breadcrumb.name)|join('\\') ~ '\\' ~ node.name %}
3+
4+
{% embed 'components/content-header.html.twig' with {
5+
anchor: node.name,
6+
anchor_link: '#' ~ node.name,
7+
fqcn,
8+
add_edition: true,
9+
} %}
10+
{% block subheader %}
11+
<div class="content-header__subheader">Trait</div>
12+
13+
{% if node.usedTraits is not empty %}
14+
<div class="content-header__subheader">
15+
Uses
16+
{% for trait in node.usedTraits %}
17+
{{ trait|route('class:short') }}{% if not loop.last %}, {% endif %}
18+
{% endfor %}
19+
</div>
20+
{% endif %}
21+
{% endblock %}
22+
{% endembed %}

tools/php_api_ref/.phpdoc/template/interface.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% block content %}
1010
{% include 'components/breadcrumbs.html.twig' %}
1111
{% include 'components/interface-title.html.twig' %}
12-
{% include('components/element-header.html.twig') %}
12+
{% include 'components/element-header.html.twig' %}
1313
{% include 'components/constants.html.twig' %}
1414
{% include 'components/methods.html.twig' %}
1515
{% endblock %}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$(() => {
2+
$('abbr').each((index, element) => {
3+
let $this = $(element);
4+
let fqcn = $this.attr('title');
5+
if (fqcn.startsWith('\\Symfony\\') && 'a' != $this.parent().prop('tagName')) {
6+
let href = 'https://github.com/symfony/symfony/blob/' + symfonyVersion + '/src' + fqcn.replaceAll('\\', '/') + '.php';
7+
$this.wrap('<a href="' + href + '" class="external">');
8+
}
9+
});
10+
})

tools/php_api_ref/.phpdoc/template/layout.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@
6868
<script src="js/search_custom.js"></script>
6969
<script src="js/copy_to_clipboard.js"></script>
7070
<script src="js/version_switcher_custom.js"></script>
71+
<script src="js/external-links.js"></script>
7172
</body>
7273
</html>

0 commit comments

Comments
 (0)