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