-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparseDesc.php
61 lines (52 loc) · 1.51 KB
/
parseDesc.php
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
<?php
/**
* in $params
* $entityName => entity name like "contact", "email"
* $baseDir => Directory path to base civicrm, like "/path/to/civicrm"
* $content => current full doc content
*/
/**
* @docmaker_start
* # Title 1
* ## Title 2
* jasdkfj
* sdfs
* ### Title 3
* @docmaker_end
*/
function doParseDesc($params) {
extract($params);
$fileName = $baseDir .'/tests/phpunit/api/v3/'.$entityName.'Test.php';
$docComments = array_filter(
token_get_all( file_get_contents( $fileName ) ), function($entry) {
return $entry[0] == T_DOC_COMMENT;
}
);
$replaceDesc = "";
foreach($docComments as $comments) {
$fileDocComment = $comments[1];
$fileDocComment = trim($fileDocComment, '/**');
$fileDocComment = preg_replace('/^\s+\*[ ]*/m', '', $fileDocComment);
preg_match('#@docmaker_intro_start(.+)@docmaker_intro_end#s', $fileDocComment, $matches);
if (!empty($matches[1])) {
$lines = explode("\n", $matches[1]);
$tplParams = array();
foreach($lines as $line) {
preg_match('/^@(\w+)\s+(.*)$/', $line, $matches);
if (!empty($matches)) {
genDoc::$_smarty->assign($matches[1], $matches[2]);
}
elseif(!empty(trim($line))){
$replaceDesc .= $line;
}
}
// only accept first per doc
break;
}
}
$search = "@DESC@";
$content = str_replace($search, $replaceDesc, $content);
$content = genDoc::$_smarty->fetch('string:'.$content);
$params['content'] = $content;
return $params;
}