IPReflectionCommentParser.class.php
4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Class for parsing the comment blocks for classes, functions
* methods and properties.
*
* The class parses the commentblock and extracts certain
* documentation tags and the (full/small) description
*
*@author KnowledgeTree Team
*@package Webservice
*@version Version 0.9
*/
class IPReflectionCommentParser{
/**
* @var string Contains the full commen text
*/
public $comment;
/**
* @var object refence to the IPReflection(Class|Method|Property)
*/
public $obj;
/** @var boolean */
public $smallDescriptionDone;
/** @var boolean */
public $fullDescriptionDone;
/**
* Constructor, initiateds the parse function
*
* @param string Commentaar block
* @param string Defines if its the comment for a class, public of function
*/
function __construct($comment, $obj) {
$this->comment = $comment;
$this->obj = $obj;
$this->parse();
}
/**
* parses the comment, line for line
*
* Will take the type of comment (class, property or function) as an
* argument and split it up in lines.
* @param string Defines if its the comment for a class, public of function
* @return void
*/
function parse() {
//reset object
$descriptionDone = false;
$this->fullDescriptionDone = false;
//split lines
$lines = split("\n", $this->comment);
//check lines for description or tags
foreach ($lines as $line) {
$pos = strpos($line,"* @");
if (trim($line) == "/**" || trim($line) == "*/") { //skip the start and end line
}elseif (!($pos === false)) { //comment
$this->parseTagLine(substr($line,$pos+3));
$descriptionDone=true;
}elseif(!$descriptionDone){
$this->parseDescription($line);
}
}
//if full description is empty, put small description in full description
if (trim(str_replace(Array("\n","\r"), Array("", ""), $this->obj->fullDescription)) == "")
$this->obj->fullDescription = $this->obj->smallDescription;
}
/**
* Parses the description to the small and full description properties
*
* @param string The description line
* @return void
*/
function parseDescription($descriptionLine) {
if(strpos($descriptionLine,"*") <= 2) $descriptionLine = substr($descriptionLine, (strpos($descriptionLine,"*") + 1));
//geen lege comment regel indien al in grote omschrijving
if(trim(str_replace(Array("\n","\r"), Array("", ""), $descriptionLine)) == ""){
if($this->obj->fullDescription == "")
$descriptionLine = "";
$this->smallDescriptionDone = true;
}
if(!$this->smallDescriptionDone)//add to small description
$this->obj->smallDescription.=$descriptionLine;
else{//add to full description
$this->obj->fullDescription.=$descriptionLine;
}
}
/**
* Parses a tag line and extracts the tagname and values
*
* @param string The tagline
* @return void
*/
function parseTagLine($tagLine) {
$tagArr = explode(" ", $tagLine);
$tag = $tagArr[0];
switch(strtolower($tag)){
case 'abstract':
$this->obj->abstract = true; break;
case 'access':
$this->obj->isPrivate = (strtolower(trim($tagArr[1]))=="private")?true:false;
break;
case 'author':
unset($tagArr[0]);
$this->obj->author = implode(" ",$tagArr);
break;
case 'copyright':
unset($tagArr[0]);
$this->obj->copyright = implode(" ",$tagArr);
break;
case 'deprecated':
case 'deprec':
$this->obj->deprecated = true;
break;
case 'extends': break;
case 'global':
$this->obj->globals[] = $tagArr[1];
break;
case 'param':
$o = new stdClass();
$o->type = trim($tagArr[1]);
$o->comment = implode(" ",$tagArr);
$this->obj->params[] = $o;
break;
case 'return':
$this->obj->return = trim($tagArr[1]); break;
case 'link':break;
case 'see':break;
case 'since':
$this->obj->since = trim($tagArr[1]); break;
case 'static':
$this->obj->static = true; break;
case 'throws':
unset($tagArr[0]);
$this->obj->throws = implode(" ",$tagArr);
break;
case 'todo':
unset($tagArr[0]);
$this->obj->todo[] = implode(" ",$tagArr);
break;
case 'var':
$this->obj->type = trim($tagArr[1]);
unset($tagArr[0],$tagArr[1]);
$comment=implode(" ",$tagArr);
//check if its an optional property
$this->obj->optional = strpos($comment,"[OPTIONAL]") !== FALSE;
$this->obj->autoincrement = strpos($comment,"[AUTOINCREMENT]") !== FALSE;
$this->obj->description = str_replace("[OPTIONAL]", "", $comment);
break;
case 'version':
$this->obj->version = $tagArr[1];
break;
default:
//echo "\nno valid tag: '".strtolower($tag)."' at tagline: '$tagLine' <br>";
//do nothing
}
}
}
?>