1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Reflection;
9:
10: use Nette;
11: use Nette\Utils\ObjectMixin;
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: class ClassType extends \ReflectionClass
46: {
47:
48:
49: 50: 51: 52:
53: public static function from($class)
54: {
55: return new static($class);
56: }
57:
58:
59: public function __toString()
60: {
61: return $this->getName();
62: }
63:
64:
65: 66: 67: 68:
69: public function is($type)
70: {
71: return $this->isSubclassOf($type) || strcasecmp($this->getName(), ltrim($type, '\\')) === 0;
72: }
73:
74:
75:
76:
77:
78: 79: 80:
81: public function getConstructor()
82: {
83: return ($ref = parent::getConstructor()) ? Method::from($this->getName(), $ref->getName()) : NULL;
84: }
85:
86:
87: 88: 89:
90: public function getExtension()
91: {
92: return ($name = $this->getExtensionName()) ? new Extension($name) : NULL;
93: }
94:
95:
96: 97: 98:
99: public function getInterfaces()
100: {
101: $res = array();
102: foreach (parent::getInterfaceNames() as $val) {
103: $res[$val] = new static($val);
104: }
105: return $res;
106: }
107:
108:
109: 110: 111:
112: public function getMethod($name)
113: {
114: return new Method($this->getName(), $name);
115: }
116:
117:
118: 119: 120:
121: public function getMethods($filter = -1)
122: {
123: foreach ($res = parent::getMethods($filter) as $key => $val) {
124: $res[$key] = new Method($this->getName(), $val->getName());
125: }
126: return $res;
127: }
128:
129:
130: 131: 132:
133: public function getParentClass()
134: {
135: return ($ref = parent::getParentClass()) ? new static($ref->getName()) : NULL;
136: }
137:
138:
139: 140: 141:
142: public function getProperties($filter = -1)
143: {
144: foreach ($res = parent::getProperties($filter) as $key => $val) {
145: $res[$key] = new Property($this->getName(), $val->getName());
146: }
147: return $res;
148: }
149:
150:
151: 152: 153:
154: public function getProperty($name)
155: {
156: return new Property($this->getName(), $name);
157: }
158:
159:
160:
161:
162:
163: 164: 165: 166: 167:
168: public function hasAnnotation($name)
169: {
170: $res = AnnotationsParser::getAll($this);
171: return !empty($res[$name]);
172: }
173:
174:
175: 176: 177: 178: 179:
180: public function getAnnotation($name)
181: {
182: $res = AnnotationsParser::getAll($this);
183: return isset($res[$name]) ? end($res[$name]) : NULL;
184: }
185:
186:
187: 188: 189: 190:
191: public function getAnnotations()
192: {
193: return AnnotationsParser::getAll($this);
194: }
195:
196:
197: 198: 199: 200:
201: public function getDescription()
202: {
203: return $this->getAnnotation('description');
204: }
205:
206:
207:
208:
209:
210: public function __call($name, $args)
211: {
212: return ObjectMixin::call($this, $name, $args);
213: }
214:
215:
216: public function &__get($name)
217: {
218: return ObjectMixin::get($this, $name);
219: }
220:
221:
222: public function __set($name, $value)
223: {
224: ObjectMixin::set($this, $name, $value);
225: }
226:
227:
228: public function __isset($name)
229: {
230: return ObjectMixin::has($this, $name);
231: }
232:
233:
234: public function __unset($name)
235: {
236: ObjectMixin::remove($this, $name);
237: }
238:
239: }
240: