-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemAnnotation.php
96 lines (91 loc) · 2.57 KB
/
SystemAnnotation.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
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
<?php
namespace BlueSeed;
/**
*
* The controller to support interpretation of requests
* @author ivonascimento <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @package system
*
*/
class SystemAnnotation {
private $dados = Array();
private $methodName;
private $type;
private $propertyName;
private $class;
private function __construct($class,$type, $method=null, $property=null){
$this->type = $type;
$this->methodName = $method;
$this->propertyName = $method;
$this->class = $class;
$this->parse();
}
public static function createasProperty($class, $propertyName)
{
return New SystemAnnotation($class, "property", NULL, $propertyName);
}
public static function createasMethod($class, $methodName)
{
return New SystemAnnotation($class, "method", $methodName);
}
public static function createasClass($class)
{
return New SystemAnnotation($class, "class");
}
private function getReflectionClass(){
switch($this->type) {
case "class" :
$reflection = new \ReflectionClass($this->class);
break;
case "property":
$reflection = new \ReflectionProperty($this->class, $this->propertyName);
break;
case "method":
$reflection = new \ReflectionMethod($this->class, $this->methodName);
break;
}
return $reflection;
}
public function updateTarget($target)
{
$update = "update".ucfirst( $this->type);
$this->$update($target);
$this->parse();
}
private function updateMethod($methodName)
{
$this->methodName = $methodName;
}
private function updateClass($class)
{
$this->class = $class;
}
private function updateProperty($propertyName)
{
$this->propertyName = $propertyName;
}
private function parse(){
$docbloc = $this->getReflectionClass()->getDocComment();
$dados = explode("\n", $docbloc);
foreach ($dados as $dado){
$r = trim($dado);
if ($r != '/**' && $r!='*/' && $r!= '*'){
$r = str_replace('* ','', $r);
if (strpos($r, ' ')!== false){
$r1 = explode(' ', $r);
$this->dados[ $r1[0] ]= $r1[1];
}
}
}
}
public function exists($key){
return array_key_exists($key, $this->dados);
}
public function get($key){
if (!$this->exists($key))
return NULL;
return $this->dados[ $key ];
}
}
?>