forked from phpDocumentor/Reflection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassReflector.php
More file actions
100 lines (88 loc) · 2.39 KB
/
ClassReflector.php
File metadata and controls
100 lines (88 loc) · 2.39 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2012 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection;
use PHPParser_Node_Name;
use PHPParser_Node_Stmt_Class;
use PHPParser_Node_Stmt_TraitUse;
/**
* Provides static reflection for a class.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class ClassReflector extends InterfaceReflector
{
/** @var \PHPParser_Node_Stmt_Class */
protected $node;
/** @var string[] */
protected $traits = array();
public function parseSubElements()
{
/** @var \PHPParser_Node_Stmt_TraitUse $stmt */
foreach ($this->node->stmts as $stmt) {
if ($stmt instanceof \PHPParser_Node_Stmt_TraitUse) {
foreach ($stmt->traits as $trait) {
$this->traits[] = '\\' . (string) $trait;
}
}
}
parent::parseSubElements();
}
/**
* Returns whether this is an abstract class.
*
* @return bool
*/
public function isAbstract()
{
return (bool) ($this->node->type & PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT);
}
/**
* Returns whether this class is final and thus cannot be extended.
*
* @return bool
*/
public function isFinal()
{
return (bool) ($this->node->type & PHPParser_Node_Stmt_Class::MODIFIER_FINAL);
}
/**
* Returns a list of the names of traits used in this class.
*
* @return string[]
*/
public function getTraits()
{
return $this->traits;
}
public function getParentClass()
{
return $this->node->extends ? '\\'.(string) $this->node->extends : '';
}
/**
* BC Break: used to be getParentInterfaces
*
* @return string[] Names of interfaces the class implements.
*/
public function getInterfaces()
{
$names = array();
if ($this->node->implements) {
/** @var PHPParser_Node_Name */
foreach ($this->node->implements as $node) {
$names[] = '\\'.(string) $node;
}
}
return $names;
}
}