1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: */
11:
12: namespace Nette\Reflection;
13:
14: use Nette,
15: Nette\ObjectMixin;
16:
17:
18:
19: /**
20: * Reports information about a classes variable.
21: *
22: * @author David Grudl
23: */
24: class PropertyReflection extends \ReflectionProperty
25: {
26:
27: public function __toString()
28: {
29: return 'Property ' . parent::getDeclaringClass()->getName() . '::$' . $this->getName();
30: }
31:
32:
33:
34: /********************* Reflection layer ****************d*g**/
35:
36:
37:
38: /**
39: * @return Nette\Reflection\ClassReflection
40: */
41: public function getDeclaringClass()
42: {
43: return new ClassReflection(parent::getDeclaringClass()->getName());
44: }
45:
46:
47:
48: /********************* Nette\Annotations support ****************d*g**/
49:
50:
51:
52: /**
53: * Has property specified annotation?
54: * @param string
55: * @return bool
56: */
57: public function hasAnnotation($name)
58: {
59: $res = AnnotationsParser::getAll($this);
60: return !empty($res[$name]);
61: }
62:
63:
64:
65: /**
66: * Returns an annotation value.
67: * @param string
68: * @return IAnnotation
69: */
70: public function getAnnotation($name)
71: {
72: $res = AnnotationsParser::getAll($this);
73: return isset($res[$name]) ? end($res[$name]) : NULL;
74: }
75:
76:
77:
78: /**
79: * Returns all annotations.
80: * @return array
81: */
82: public function getAnnotations()
83: {
84: return AnnotationsParser::getAll($this);
85: }
86:
87:
88:
89: /********************* Nette\Object behaviour ****************d*g**/
90:
91:
92:
93: /**
94: * @return Nette\Reflection\ClassReflection
95: */
96: public static function getReflection()
97: {
98: return new Nette\Reflection\ClassReflection(get_called_class());
99: }
100:
101:
102:
103: public function __call($name, $args)
104: {
105: return ObjectMixin::call($this, $name, $args);
106: }
107:
108:
109:
110: public function &__get($name)
111: {
112: return ObjectMixin::get($this, $name);
113: }
114:
115:
116:
117: public function __set($name, $value)
118: {
119: return ObjectMixin::set($this, $name, $value);
120: }
121:
122:
123:
124: public function __isset($name)
125: {
126: return ObjectMixin::has($this, $name);
127: }
128:
129:
130:
131: public function __unset($name)
132: {
133: throw new \MemberAccessException("Cannot unset the property {$this->reflection->name}::\$$name.");
134: }
135:
136: }
137: