Skip to content

Commit 785a47b

Browse files
committed
update reference template and some phpdoc comments
1 parent 8866cff commit 785a47b

15 files changed

+323
-83
lines changed

docs/_data/menu.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
Introduction: /
2-
Configuration: /configuration.html
3-
Entity Definition: /entityDefinition.html
4-
Working With Entities: /entities.html
5-
Use Filters: /filters.html
6-
Relation Definition: /relationDefinition.html
7-
Working With Relations: /relations.html
8-
Events and Observers: /events.html
9-
Use QueryBuilder: /querybuilder.html
10-
Validate Data: /validate.html
11-
Bulk Inserts: /bulkInserts.html
12-
Testing: /testing.html
1+
Introduction: /orm/
2+
Configuration: /orm/configuration
3+
Entity Definition: /orm/entityDefinition
4+
Working With Entities: /orm/entities
5+
Use Filters: /orm/filters
6+
Relation Definition: /orm/relationDefinition
7+
Working With Relations: /orm/relations
8+
Events and Observers: /orm/events
9+
Use QueryBuilder: /orm/querybuilder
10+
Validate Data: /orm/validate
11+
Bulk Inserts: /orm/bulkInserts
12+
Testing: /orm/testing
1313

14-
' ': /placeholder.html
14+
' ': /orm/placeholder
1515

16-
API Reference: /reference.html
16+
API Reference: /orm/reference

docs/_layouts/default.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="chrome=1">
6-
<title>tflori/orm - {{ page.title }}</title>
6+
<title>{{ page.title }} - tflori/orm</title>
77
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700' rel='stylesheet' type='text/css'>
8-
<link rel="stylesheet" href="stylesheets/styles.css">
9-
<link rel="stylesheet" href="stylesheets/highlight.css">
8+
<link rel="stylesheet" href="/orm/stylesheets/styles.css">
9+
<link rel="stylesheet" href="/orm/stylesheets/highlight.css">
1010
<meta name="viewport" content="width=device-width">
1111
<!--[if lt IE 9]>
1212
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
@@ -22,7 +22,7 @@ <h1>tflori/orm</h1>
2222
<ul>
2323
{% for link in site.data.menu %}
2424
<li {% if page.url == link[1] %}class="selected"{% endif %}>
25-
<a href=".{{ link[1] }}">{{ link[0] }}</a>
25+
<a href="{{ link[1] }}">{{ link[0] }}</a>
2626
</li>
2727
{% endfor %}
2828
</ul>
@@ -51,7 +51,7 @@ <h1>tflori/orm</h1>
5151
<p><small>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
5252
</footer>
5353
</div>
54-
<script src="javascripts/scale.fix.js"></script>
54+
<script src="/orm/javascripts/scale.fix.js"></script>
5555

5656
</body>
5757
</html>
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
use Twig\Extension\AbstractExtension;
4+
use Twig\TwigFilter;
5+
use Twig\TwigFunction;
6+
7+
class MarkdownTwigExtension extends AbstractExtension
8+
{
9+
const NAMESPACE_LINKS = [
10+
'ORM\\' => '/orm/reference',
11+
'Illuminate\\Support\\' => '/orm/reference',
12+
];
13+
public function getFilters()
14+
{
15+
return [
16+
new TwigFilter('linkClasses', [$this, 'linkClasses'], ['is_safe' => ['all']]),
17+
new TwigFilter('lcFirst', 'lcfirst'),
18+
new TwigFilter('join', function ($value, $glue = ', ') {
19+
if (is_array($value)) {
20+
return implode($glue, $value);
21+
}
22+
23+
if ($value instanceof \phpDocumentor\Descriptor\Collection) {
24+
return implode($glue, $value->getAll());
25+
}
26+
27+
return $value;
28+
}),
29+
];
30+
}
31+
32+
public function getFunctions()
33+
{
34+
return [
35+
new TwigFunction('generateSignature', [$this, 'generateSignature'], ['is_safe' => ['html']]),
36+
];
37+
}
38+
39+
public function linkClasses($value)
40+
{
41+
return preg_replace_callback(
42+
'/\\\\([A-Za-z0-9_\\\\]+)/',
43+
function ($match) {
44+
$type = $match[1];
45+
foreach (self::NAMESPACE_LINKS as $namespace => $link) {
46+
if (strncmp($type, $namespace, strlen($namespace)) === 0) {
47+
return '[' . $type . '](' . $link . '/' . str_replace('\\', '/', $type) . ')';
48+
}
49+
}
50+
return $type;
51+
},
52+
$value
53+
);
54+
}
55+
56+
/**
57+
* @param \phpDocumentor\Descriptor\MethodDescriptor $method
58+
*/
59+
public function generateSignature($method, $maxLength = null)
60+
{
61+
$signature = 'function ' . $method->getName() . '(';
62+
$args = [];
63+
64+
foreach ($method->getArguments() as $argument) {
65+
$arg = '$' . $argument->getName();
66+
if ($argument->isByReference()) {
67+
$arg = '&' . $arg;
68+
}
69+
if ($argument->getType() !== 'mixed') {
70+
$arg = $argument->getType() . ' ' . $arg;
71+
}
72+
if ($argument->getDefault()) {
73+
$arg = $arg . ' = ' . $argument->getDefault();
74+
}
75+
$args[] = $arg;
76+
}
77+
78+
$signature .= implode(', ', $args) . ')';
79+
80+
if ($method->isStatic()) {
81+
$signature = 'static ' . $signature;
82+
}
83+
84+
$signature = $method->getVisibility() . ' ' . $signature;
85+
86+
if ($method->isAbstract()) {
87+
$signature = 'abstract ' . $signature;
88+
}
89+
90+
if ($method->isFinal()) {
91+
$signature = 'final ' . $signature;
92+
}
93+
94+
if ($method->getResponse() && $method->getName() !== '__construct') {
95+
$type = $method->getResponse()->getType();
96+
if ($type === 'self') {
97+
$signature .= ': ' . $method->getParent()->getName();
98+
} else {
99+
$signature .= ': ' . $type;
100+
}
101+
}
102+
103+
if ($maxLength && strlen($signature) > $maxLength) {
104+
if (preg_match('/^(.*)\((.*)\)($|:.*$)/', $signature, $matches)) {
105+
$lines = [$matches[1] . '('];
106+
$args = explode(', ', $matches[2]);
107+
foreach ($args as $arg) {
108+
$lines[] = ' ' . $arg . ', ';
109+
}
110+
$lines[] = ')' . $matches[3];
111+
$signature = implode("\n", $lines);
112+
}
113+
}
114+
115+
return $signature;
116+
}
117+
}

docs/_reference/class.md.twig

+42-22
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
1-
### {{ node.FullyQualifiedStructuralElementName|trim('\\') }}
1+
---
2+
layout: default
3+
title: API Reference - {{ node.FullyQualifiedStructuralElementName|trim('\\') }}
4+
---
5+
<small>» [API Reference](/orm/reference) » {{ node.FullyQualifiedStructuralElementName|trim('\\') }}</small>
6+
7+
8+
## {{ node.FullyQualifiedStructuralElementName|trim('\\') }}
9+
10+
### Table of Contents
11+
12+
* [Abstract](#abstract)
13+
{% if node.constants is not empty %}{#
14+
#}* [Constants](#constants)
15+
{% endif %}{#
16+
#}{% if (node.inheritedProperties.merge(node.properties)) is not empty %}{#
17+
#}* [Properties](#properties)
18+
{% endif %}{#
19+
#}{% if node.methods is not empty %}{#
20+
#}* [Methods](#methods)
21+
{# #}{% for method in node.inheritedMethods.merge(node.methods)|sort_asc %}{#
22+
#} * [{% if method.isStatic() %}{{ node.name }}::{% else %}${{ node.name|lcFirst }}->{% endif %}{{ method.name }}](#{{ node.FullyQualifiedStructuralElementName|replace({'\\': ''})|lower }}{{ method.name|lower }}) - {{ method.summary }}
23+
{# #}{% endfor %}{#
24+
#}{% endif %}
25+
26+
### Abstract
227

328
{% if node.parent is not empty %}
4-
**Extends:** {% for parent in node.parent %}
5-
[{{ parent.FullyQualifiedStructuralElementName|trim('\\') }}](#{{ parent.FullyQualifiedStructuralElementName|replace({'\\': ''})|lower }})
6-
{% else %}[{{ node.parent.FullyQualifiedStructuralElementName|trim('\\') }}](#{{ node.parent.FullyQualifiedStructuralElementName|replace({'\\': ''})|lower }})
7-
{% endfor %}
29+
**Extends:** {{ node.parent|join|linkClasses }}
830
{% endif %}
931

1032
{% if node.interfaces is not empty %}
11-
**Implements:** {% for interface in node.interfaces %}
12-
[{{ interface.FullyQualifiedStructuralElementName|trim('\\') }}](#{{ interface.FullyQualifiedStructuralElementName|replace({'\\': ''})|lower }})
13-
{% endfor %}
33+
**Implements:** {{ node.interfaces|join|linkClasses }}
1434
{% endif %}
1535

1636
{% if node.summary is not empty and node.summary != 'Class '~node.name %}
17-
#### {{ node.summary|raw }}
37+
### {{ node.summary|raw }}
1838
{% endif %}
1939

2040
{{ node.description|raw }}
2141

22-
{% if node.deprecated %}* **Warning:** this class is **deprecated**. This means that this class will likely be removed in a future version.
42+
{% if node.deprecated %}**Warning:** this class is **deprecated**. This means that this class will likely be removed in a future version.
2343
{% endif %}
2444

2545
{% if node.tags.see is not empty or node.tags.link is not empty %}
2646
**See Also:**
2747

2848
{% for see in node.tags.see %}
29-
* {{ see.reference }} {% if see.description %}- {{ see.description|raw }}{% endif %}
49+
* {{ see.reference|linkClasses }} {% if see.description is not empty %} - {{ see.description|raw }}{% endif %}
3050
{% endfor %}
3151
{% for link in node.tags.link %}
3252
* [{{ link.description ?: link.link }}]({{ link.link }})
@@ -35,7 +55,7 @@
3555
{% endif %}{# node.tags.see || node.tags.link #}
3656

3757
{% if node.constants is not empty %}
38-
#### Constants
58+
### Constants
3959

4060
| Name | Value |
4161
|------|-------|
@@ -46,12 +66,12 @@
4666
{% endif %}
4767

4868
{% if (node.inheritedProperties.merge(node.properties)) is not empty %}
49-
#### Properties
69+
### Properties
5070

5171
| Visibility | Name | Type | Description |
5272
|------------|------|------|---------------------------------------|
53-
{% for property in node.inheritedProperties.merge(node.properties).sortBy('name') %}
54-
| **{{ property.visibility }}{{ property.isStatic ? ' static' }}** | `${{ property.name }}` | {% if property.types is not empty %}**{{ property.types ? property.types|join(' &#124; ')|replace({'<mixed,': '&lt;', (node.namespace.FullyQualifiedStructuralElementName~'\\'): '', '\\': ' \\ '})|raw }}**{% endif %} | {{ property.summary }} |
73+
{% for property in node.inheritedProperties.merge(node.properties) %}
74+
| **{{ property.visibility }}{{ property.isStatic ? ' static' }}** | `${{ property.name }}` | {% if property.type is not empty %}**{{ property.type|linkClasses|replace({'|': '\\|'}) }}**{% endif %} | {{ property.summary }} |
5575
{% endfor %}
5676

5777
{% endif %}
@@ -61,14 +81,14 @@
6181
#### Methods
6282

6383
{% for method in node.inheritedMethods.merge(node.methods)|sort_asc %}
64-
* [{{ method.name }}](#{{ node.FullyQualifiedStructuralElementName|replace({'\\': ''})|lower }}{{ method.name|lower }}) {{ method.summary }}
65-
{% endfor %}
84+
#### {{ node.FullyQualifiedStructuralElementName|trim('\\') }}::{{ method.name }}
6685

67-
{% for method in node.inheritedMethods.merge(node.methods)|sort_asc %}
68-
{% include 'method.md.twig' %}
69-
{% endfor %}
86+
{% include './method.md.twig' %}
7087

71-
{% endif %}
88+
<small style="color: #555;">{{ node.FullyQualifiedStructuralElementName|trim('\\') }}::{{ method.name }}</small>
7289

73-
---
90+
[↑ top](#)
91+
<hr />
92+
{% endfor %}
7493

94+
{% endif %}

docs/_reference/index.md.twig

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1+
{% import 'macros.twig' as macros %}
12
---
23
layout: default
34
title: API Reference
4-
permalink: /reference.html
55
---
66
## API Reference
77

8+
<small>» API Reference</small>
9+
810
{% for namespace in project.indexes.namespaces|sort %}
911
{% if not namespace.classes.merge(namespace.interfaces) is empty %}
1012

1113
### {{ namespace|trim('\\') }}
1214

13-
{% for node in namespace.classes.merge(namespace.interfaces)|sort_asc %}
14-
* [{{ node.name }}](#{{ node.FullyQualifiedStructuralElementName|replace({'\\': ''})|lower }})
15+
{% for node in namespace.classes.merge(namespace.interfaces).merge(namespace.traits)|sort_asc %}
16+
* {{ node.FullyQualifiedStructuralElementName|linkClasses }}
1517
{% endfor %}
1618

1719
{% endif %}
1820
{% endfor %}
1921

2022
---
21-
22-
{% for node in project.indexes.classes.merge(project.indexes.interfaces)|sort_asc %}
23-
{% include 'class.md.twig' %}
24-
{% endfor %}

docs/_reference/macros.twig

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{% macro generateSignature(method, maxLength) %}{#
2+
#}{% set signature = 'function ' ~ method.name ~ '(' %}{#
3+
4+
#}{% set args = [] %}{#
5+
6+
#}{% for argument in method.arguments %}{#
7+
#}{% set arg = '$' ~ argument.name %}{#
8+
#}{% if argument.byReference %}{#
9+
#}{% set arg = '&' ~ arg %}{#
10+
#}{% endif %}{#
11+
#}{% if argument.getType() is not same as('mixed') %}{#
12+
#}{% set arg = argument.getType() ~ ' ' ~ arg %}{#
13+
#}{% endif %}{#
14+
#}{% if argument.default %}{#
15+
#}{% set arg = arg ~ ' = ' ~ argument.default %}{#
16+
#}{% endif %}{#
17+
#}{% set args = args|merge([arg]) %}{#
18+
#}{% endfor %}{#
19+
20+
#}{% set signature = signature ~ args|join(', ') ~ ')' %}{#
21+
22+
#}{% if method.static %}{#
23+
#}{% set signature = 'static ' ~ signature %}{#
24+
#}{% endif %}{#
25+
26+
#}{% set signature = method.visibility ~ ' ' ~ signature %}{#
27+
28+
#}{% if method.abstract %}{#
29+
#}{% set signature = 'abstract ' ~ signature %}{#
30+
#}{% endif %}{#
31+
32+
#}{% if method.final %}{#
33+
#}{% set signature = 'final ' ~ signature %}{#
34+
#}{% endif %}{#
35+
36+
#}{% if method.response and method.name != '__construct' %}{#
37+
#}{% set type = method.response.type %}{#
38+
#}{% if type == 'self' %}{#
39+
#}{% set signature = signature ~ ': ' ~ method.parent.name %}{#
40+
#}{% else %}{#
41+
#}{% set signature = signature ~ ': ' ~ type %}{#
42+
#}{% endif %}{#
43+
#}{% endif %}{#
44+
45+
#}{% if maxLength and maxLength < signature|length %}{#
46+
#}{% if signature matches '/^(.*)\((.*)\)($|:.*$)/' %}{#
47+
#}{% set match = signature|split('(', 2) %}{#
48+
#}{% set lines = [match[0] ~ '('] %}{#
49+
#}{% set match = match[1]|split(')', 2) %}{#
50+
#}{% for arg in match[0]|split(', ') %}{#
51+
#}{% set line = ' ' ~ arg ~ ', ' %}{#
52+
#}{% set lines = lines|merge([line]) %}{#
53+
#}{% endfor %}{#
54+
#}{% set lines = lines|merge([')' ~ match[1]]) %}{#
55+
#}{% set signature = lines|join('\n') %}{#
56+
#}{% endif %}{#
57+
#}{% endif %}{#
58+
59+
#}{{ signature|raw }}{#
60+
#}{% endmacro %}
61+
62+
{% macro linkTypes(value, this) %}{#
63+
#}{% set types = value|split('|') %}{#
64+
#}{% for type in types %}{#
65+
#}{% set type = type|trim('\\') %}{#
66+
#}{% set cleanType = type|split('[]', 2)[0] %}{#
67+
#}{% set brackets = type|slice(cleanType|length) %}{#
68+
#}{% if cleanType starts with 'ORM\\' %}{#
69+
#}[{{ cleanType }}](/orm/reference/{{ cleanType|replace({'\\': '/'}) }}){#
70+
#}{% elseif cleanType == '$this' %}{#
71+
#}[{{ cleanType }}](#{{ this }}){#
72+
#}{% else %}{{ cleanType }}{% endif %}{#
73+
#}{{ brackets }}{#
74+
#}{% if not loop.last %}|{% endif %}{#
75+
#}{% endfor %}{#
76+
#}{% endmacro %}

0 commit comments

Comments
 (0)