1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017 Julius Härtl <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Julius Härtl <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace JuliusHaertl\PHPDocToRst\Builder; |
25
|
|
|
|
26
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Param; |
27
|
|
|
use phpDocumentor\Reflection\Php\Interface_; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class InterfaceFileBuilder extends FileBuilder { |
31
|
|
|
|
32
|
|
|
const SECTION_BEFORE_DESCRIPTION = self::class . '::SECTION_BEFORE_DESCRIPTION'; |
33
|
|
|
const SECTION_AFTER_DESCRIPTION = self::class . '::SECTION_AFTER_DESCRIPTION'; |
34
|
|
|
|
35
|
|
|
protected function render() { |
36
|
|
|
/** @var Interface_ $interface */ |
37
|
|
|
$interface = $this->element; |
38
|
|
|
|
39
|
|
|
$namespace = str_replace('\\' . $interface->getName(), '', $interface->getFqsen()); |
40
|
|
|
|
41
|
|
|
$docBlock = $interface->getDocBlock(); |
42
|
|
|
$this->addH1(self::escape($interface->getFqsen()))->addLine(); |
43
|
|
|
if($namespace !== '') { |
44
|
|
|
$this->beginPhpDomain('namespace', substr($namespace, 1), false); |
45
|
|
|
} |
46
|
|
|
$this->beginPhpDomain('interface', $interface->getName(), false); |
47
|
|
|
|
48
|
|
|
$this->addLine(); |
49
|
|
|
|
50
|
|
|
$this->callExtensions(self::SECTION_BEFORE_DESCRIPTION); |
51
|
|
|
|
52
|
|
|
$this->addDocBlockDescription($docBlock); |
53
|
|
|
|
54
|
|
|
// Add class details |
55
|
|
|
$parents = ''; |
56
|
|
|
foreach ($interface->getParents() as $parent) { |
57
|
|
|
$parents .= $this->getLink('interface', $parent) . ' '; |
58
|
|
|
} |
59
|
|
|
$this->addFieldList('Parent', $parents)->addLine(); |
60
|
|
|
|
61
|
|
|
$this->callExtensions(self::SECTION_AFTER_DESCRIPTION); |
62
|
|
|
|
63
|
|
|
foreach ($interface->getMethods() as $method) { |
64
|
|
|
/* Render method */ |
65
|
|
|
$docBlock = $method->getDocBlock(); |
66
|
|
|
$params = []; |
67
|
|
|
if ($docBlock !== null) { |
68
|
|
|
/** @var Param $param */ |
69
|
|
|
foreach ($docBlock->getTagsByName('param') as $param) { |
70
|
|
|
$params[$param->getVariableName()] = $param; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
$args = ''; |
74
|
|
|
foreach ($method->getArguments() as $argument) { |
75
|
|
|
$args .= '$' . $argument->getName() . ', '; |
76
|
|
|
} |
77
|
|
|
$args = substr($args, 0, -2); |
78
|
|
|
$modifiers = $method->getVisibility(); |
79
|
|
|
$modifiers .= $method->isAbstract() ? ' abstract' : ''; |
80
|
|
|
$modifiers .= $method->isFinal() ? ' final' : ''; |
81
|
|
|
$modifiers .= $method->isStatic() ? ' static' : ''; |
82
|
|
|
$this->addLine('.. rst-class:: ' . $modifiers)->addLine(); |
83
|
|
|
$this->indent(); |
84
|
|
|
|
85
|
|
|
$this->beginPhpDomain('method', $method->getName() . '(' . $args . ')'); |
86
|
|
|
$this->addLine(); |
87
|
|
|
$this->addDocBlockDescription($docBlock); |
88
|
|
|
|
89
|
|
|
if (!empty($params)) { |
90
|
|
|
foreach ($method->getArguments() as $argument) { |
91
|
|
|
/** @var Param $param */ |
92
|
|
|
$param = $params[$argument->getName()]; |
93
|
|
|
if ($param !== null) $this->addMultiline(':param ' . RstBuilder::escape($param->getType()) . ' $' . $argument->getName() . ': ' . RstBuilder::escape($param->getDescription()), true); |
94
|
|
|
} |
95
|
|
|
foreach ($docBlock->getTags() as $tag) { |
96
|
|
|
$this->addDocblockTag($tag->getName(), $docBlock); |
97
|
|
|
} |
98
|
|
|
$this->addLine(); |
99
|
|
|
} |
100
|
|
|
$this->unindent(); |
101
|
|
|
$this->endPhpDomain('method'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Render extension custom views before the descriptioj |
107
|
|
|
*/ |
108
|
|
|
private function callExtensions($type) { |
109
|
|
|
foreach ($this->extensions as $extension) { |
110
|
|
|
$extension->render($type, $this); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |