forked from locutusjs/locutus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocBlock.php
More file actions
85 lines (72 loc) · 2.65 KB
/
Copy pathDocBlock.php
File metadata and controls
85 lines (72 loc) · 2.65 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
<?php
Class PHPJS_DocBlock {
protected $_examples = array();
protected $_notes = array();
protected $_dependencies = array();
protected $_authors = array();
protected $_processed = 0;
public $config = array(
"mapping"=>array(
"-"=>"dependencies",
"+"=>"authors",
"%"=>"notes",
"*"=>"examples",
)
);
protected $_docBlock = "";
public function getExamples() {
return $this->_examples;
}
public function getNotes() {
return $this->_notes;
}
public function getAuthors() {
return $this->_authors;
}
public function getDependencies() {
return $this->_dependencies;
}
public function PHPJS_DocBlock($docBlock) {
$this->_docBlock = implode("\n", str_replace("\r", "", $docBlock));
$this->parseDocBlock();
}
public function parseDocBlock() {
if ($this->_processed > 0) {
return $this->_processed;
}
$mapping = $this->config["mapping"];
// Match all meaningful comment lines
preg_match_all('/^[\s]*\/\/[\s]*(['.preg_quote(implode('', array_keys($mapping))).'])[\s]*(.+)/m',
$this->_docBlock,
$matches);
// Loop over meaningful comment lines
foreach ($matches[1] as $k=>$match) {
// Determine what kind of comment line this is
$map = $mapping[$match];
if ($map == "examples" ) {
// Special hierarchy handling for multiple examples
preg_match('/[\s]*(\w+) (\d+):[\s]*(.+)/', trim($matches[2][$k]), $r);
if ($r[1] == "example") {
$this->_examples[$r[2]][$r[1]][] = $r[3];
} else {
$this->_examples[$r[2]][$r[1]] = $r[3];
}
} elseif ($map == "authors" ) {
preg_match('/[\s]*(\w+)([^:]*):[\s]*([^(]+)(.*)/', trim($matches[2][$k]), $r);
$url = trim(str_replace(array('(', ')'), '', $r[4]));
$this->_authors[$r[1]][trim($r[3])] = $url;
} elseif ($map == "dependencies" ) {
$this->_dependencies[] = str_replace("depends on: ", "", $matches[2][$k]);
} elseif ($map == "notes" ) {
$this->_notes[] = $matches[2][$k];
} else {
// Store meaningful comment line
throw new PHPJS_Exception("Unknown: $map");
//$info[$map][] = $matches[2][$k];
}
}
$this->_processed++;
return $this->_processed;
}
}
?>