1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: */
7:
8: namespace Nette\Reflection;
9:
10: use Nette;
11: use Nette\Utils\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: public function __call($name, $args)
104: {
105: return ObjectMixin::call($this, $name, $args);
106: }
107:
108:
109: public function &__get($name)
110: {
111: return ObjectMixin::get($this, $name);
112: }
113:
114:
115: public function __set($name, $value)
116: {
117: ObjectMixin::set($this, $name, $value);
118: }
119:
120:
121: public function __isset($name)
122: {
123: return ObjectMixin::has($this, $name);
124: }
125:
126:
127: public function __unset($name)
128: {
129: ObjectMixin::remove($this, $name);
130: }
131:
132: }
133: