|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/pipe2 |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Gilmar Pupo <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* For more information, see |
|
12
|
|
|
* <https://opensource.gpupo.com/pipe2/>. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Gpupo\Pipe2\Documentor; |
|
16
|
|
|
|
|
17
|
|
|
use Gpupo\Common\Entity\Collection; |
|
18
|
|
|
use Gpupo\Pipe2\Traits\DocumentContainerTrait; |
|
19
|
|
|
use SimpleXmlElement; |
|
20
|
|
|
|
|
21
|
|
|
class Converter |
|
22
|
|
|
{ |
|
23
|
|
|
use DocumentContainerTrait; |
|
24
|
|
|
|
|
25
|
|
|
protected $list; |
|
26
|
|
|
|
|
27
|
|
|
public function getMarkdown() |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->getDocument()->render($this->list); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(Array $parameters) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->setDocument(new Document()); |
|
35
|
|
|
$this->list = $this->parserFromFile($parameters['inputFile']); |
|
36
|
|
|
|
|
37
|
|
|
file_put_contents($parameters['outputFile'], $this->getMarkdown()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function parserFromFile($file) |
|
41
|
|
|
{ |
|
42
|
|
|
$xml = simplexml_load_file($file); |
|
43
|
|
|
|
|
44
|
|
|
return $this->parseItens($xml); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function normalizeFullName($fullName) |
|
48
|
|
|
{ |
|
49
|
|
|
return ltrim((string) $fullName, '\\'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function parseParent($raw) |
|
53
|
|
|
{ |
|
54
|
|
|
$list = []; |
|
55
|
|
|
if (!empty($raw)) { |
|
56
|
|
|
foreach ($raw as $parent) { |
|
57
|
|
|
$list[] = ltrim((string) $parent, '\\'); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $list; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function parseItens(SimpleXmlElement $xml) |
|
65
|
|
|
{ |
|
66
|
|
|
$list = []; |
|
67
|
|
|
foreach ($xml->xpath('file/class|file/interface') as $class) { |
|
68
|
|
|
$name = $this->normalizeFullName($class->full_name); |
|
69
|
|
|
$list[$name] = [ |
|
70
|
|
|
'className' => $name, |
|
71
|
|
|
'shortClass' => $class->name, |
|
72
|
|
|
'namespace' => $class['namespace'], |
|
73
|
|
|
'description' => $class->docblock->description, |
|
74
|
|
|
'longDescription' => $class->docblock->{'long-description'}, |
|
75
|
|
|
'implements' => $this->parseParent($class->implements), |
|
76
|
|
|
'extends' => $this->parseParent($class->extends), |
|
77
|
|
|
'methods' => $this->parseMethods($class), |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return new Collection($list); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function parseMethods(SimpleXMLElement $class) |
|
85
|
|
|
{ |
|
86
|
|
|
$list = []; |
|
87
|
|
|
|
|
88
|
|
|
foreach ($class->method as $method) { |
|
89
|
|
|
$list[] = $this->parserMethod($method); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $list; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
protected function parseArgument($method) |
|
96
|
|
|
{ |
|
97
|
|
|
$list = []; |
|
98
|
|
|
foreach ($method->argument as $argument) { |
|
99
|
|
|
$data = get_object_vars($argument); |
|
100
|
|
|
|
|
101
|
|
|
if ($data['type'] && is_object($data['type'])) { |
|
102
|
|
|
$data['type'] = get_object_vars($data[$type]); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$filter = 'docblock/tag[@name="param" and @variable="'.$data['name'].'"]'; |
|
106
|
|
|
|
|
107
|
|
|
$tag = $method->xpath($filter); |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
$list[] = $data; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return new Collection($list); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
protected function parserMethod($method) |
|
116
|
|
|
{ |
|
117
|
|
|
return new Collection([ |
|
118
|
|
|
'name' => $method->name, |
|
119
|
|
|
'description' => (string) $method->docblock->description."\n\n".(string) $method->docblock->{'long-description'}, |
|
120
|
|
|
'visibility' => (string) $method['visibility'], |
|
121
|
|
|
'static' => ((string) $method['static']) === 'true', |
|
122
|
|
|
'arguments' => $this->parseArgument($method), |
|
123
|
|
|
]); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.