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