forked from ApiGen/ApiGen
/
CustomClassReflection.php
100 lines (77 loc) · 2.44 KB
/
CustomClassReflection.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
97
98
99
100
<?php
/**
* API Generator.
*
* Copyright (c) 2010 David Grudl (http://davidgrudl.com)
*
* This source file is subject to the "Nette license", and/or
* GPL license. For more information please see http://nette.org
*/
namespace Apigen;
use NetteX;
/**
* Smarter class/interface reflection.
* @author David Grudl
*/
class CustomClassReflection extends NetteX\Reflection\ClassReflection
{
private $package = NULL;
/**
* Returns namespace or package name.
* @return string
*/
public function getNamespaceName()
{
if ($this->package === NULL) {
if ($this->inNamespace() || $this->isInternal()) {
$this->package = parent::getNamespaceName();
} elseif ($this->hasAnnotation('package')) {
$this->package = $this->getAnnotation('package'); // found in class-level DocBlock
} elseif (preg_match('#\*\s+@package\s+(\S+)#', file_get_contents($this->getFileName()), $matches)) {
$this->package = $matches[1]; // found in page-level DocBlock
}
}
return $this->package;
}
/**
* Returns interfaces declared by inspected class.
* @return array of CustomClassReflection
*/
public function getOwnInterfaces()
{
$parent = $this->getParentClass();
return array_filter($this->getInterfaces(), function($interface) use ($parent) {
return !$parent || !$parent->implementsInterface($interface->getName());
});
}
/**
* Returns visible methods declared by inspected class.
* @return array of NetteX\Reflection\MethodReflection
*/
public function getOwnMethods()
{
$me = $this->getName();
return array_filter($this->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED), function($method) use ($me) {
return $method->declaringClass->name === $me && !$method->hasAnnotation('internal');
});
}
/**
* Returns visible properties declared by inspected class.
* @return array of NetteX\Reflection\PropertyReflection
*/
public function getOwnProperties()
{
$me = $this->getName();
return array_filter($this->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED), function($property) use ($me) {
return $property->declaringClass->name === $me && !$property->hasAnnotation('internal');
});
}
/**
* Returns constants declared by inspected class.
* @return array of string
*/
public function getOwnConstants()
{
return array_diff_assoc($this->getConstants(), $this->getParentClass() ? $this->getParentClass()->getConstants() : array());
}
}