|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wingu\OctopusCore\Reflection; |
|
4
|
|
|
|
|
5
|
|
|
use Wingu\OctopusCore\Reflection\Exceptions\RuntimeException; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* The ReflectionFunction class reports information about a function. |
|
9
|
|
|
*/ |
|
10
|
|
|
class ReflectionFunction extends \ReflectionFunction |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
use ReflectionDocCommentTrait; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Get the body of the function. |
|
17
|
|
|
* |
|
18
|
|
|
* @return string |
|
19
|
|
|
* @throws \Wingu\OctopusCore\Reflection\Exceptions\RuntimeException If the function is internal. |
|
20
|
|
|
*/ |
|
21
|
15 |
|
public function getBody() |
|
22
|
|
|
{ |
|
23
|
15 |
|
$fileName = $this->getFileName(); |
|
24
|
15 |
|
if ($fileName === false) { |
|
25
|
3 |
|
throw new RuntimeException('Can not get body of a function that is internal.'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
12 |
|
$lines = file($fileName, FILE_IGNORE_NEW_LINES); |
|
29
|
12 |
|
$lines = array_slice($lines, $this->getStartLine() - 1, ($this->getEndLine() - $this->getStartLine() + 1), |
|
30
|
12 |
|
true); |
|
31
|
12 |
|
$lines = implode("\n", $lines); |
|
32
|
|
|
|
|
33
|
12 |
|
$firstBracketPos = strpos($lines, '{'); |
|
34
|
12 |
|
$lastBracketPost = strrpos($lines, '}'); |
|
35
|
12 |
|
$body = substr($lines, $firstBracketPos + 1, $lastBracketPost - $firstBracketPos - 1); |
|
36
|
|
|
|
|
37
|
12 |
|
return trim(rtrim($body), "\n\r"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Gets a ReflectionExtension object for the extension which defined the function. |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Wingu\OctopusCore\Reflection\ReflectionExtension |
|
44
|
|
|
*/ |
|
45
|
6 |
|
public function getExtension() |
|
46
|
|
|
{ |
|
47
|
6 |
|
$extensionName = $this->getExtensionName(); |
|
48
|
6 |
|
if ($extensionName !== false) { |
|
49
|
3 |
|
return new ReflectionExtension($extensionName); |
|
50
|
|
|
} else { |
|
51
|
3 |
|
return null; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets parameters. |
|
57
|
|
|
* |
|
58
|
|
|
* @return \Wingu\OctopusCore\Reflection\ReflectionParameter[] |
|
59
|
|
|
*/ |
|
60
|
6 |
|
public function getParameters() |
|
61
|
|
|
{ |
|
62
|
6 |
|
$res = parent::getParameters(); |
|
63
|
|
|
|
|
64
|
6 |
|
foreach ($res as $key => $val) { |
|
65
|
3 |
|
$res[$key] = new ReflectionParameter($this->getName(), $val->getName()); |
|
66
|
2 |
|
} |
|
67
|
|
|
|
|
68
|
6 |
|
return $res; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|