1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of cloak. |
5
|
|
|
* |
6
|
|
|
* (c) Noritaka Horio <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace cloak\reflection; |
13
|
|
|
|
14
|
|
|
use cloak\value\LineRange; |
15
|
|
|
use cloak\result\LineResultSelectable; |
16
|
|
|
use cloak\result\MethodResult; |
17
|
|
|
use Zend\Code\Reflection\MethodReflection as ZendMethodReflection; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class MethodReflection |
22
|
|
|
* @package cloak\reflection |
23
|
|
|
*/ |
24
|
|
|
class MethodReflection implements Reflection, ResultConvertible |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Zend\Code\Reflection\MethodReflection |
29
|
|
|
*/ |
30
|
|
|
private $reflection; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param $class |
35
|
|
|
* @param string $name |
36
|
|
|
*/ |
37
|
|
|
public function __construct($class, $name = null) |
38
|
|
|
{ |
39
|
|
|
$this->reflection = new ZendMethodReflection($class, $name); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function getIdentityName() |
46
|
|
|
{ |
47
|
|
|
$template = '%s\\%s::%s'; |
48
|
|
|
$assembleContent = sprintf( |
49
|
|
|
$template, |
50
|
|
|
$this->getNamespaceName(), |
51
|
|
|
$this->getDeclaringClassName(), |
52
|
|
|
$this->getName() |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
return $assembleContent; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function getName() |
62
|
|
|
{ |
63
|
|
|
return $this->reflection->name; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getNamespaceName() |
70
|
|
|
{ |
71
|
|
|
$declaringClass = $this->reflection->getDeclaringClass(); |
72
|
|
|
return $declaringClass->getNamespaceName(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getDeclaringClassName() |
79
|
|
|
{ |
80
|
|
|
$declaringClass = $this->reflection->getDeclaringClass(); |
81
|
|
|
return $declaringClass->name; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function getLineRange() |
88
|
|
|
{ |
89
|
|
|
$startLine = $this->reflection->getStartLine(); |
90
|
|
|
$endLine = $this->reflection->getEndLine(); |
91
|
|
|
|
92
|
|
|
return new LineRange($startLine, $endLine); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
|
|
public function convertToResult(LineResultSelectable $selector) |
99
|
|
|
{ |
100
|
|
|
return new MethodResult($this, $selector); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function __toString() |
107
|
|
|
{ |
108
|
|
|
return $this->getIdentityName(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|