Source for file PropertyReflection.php

Documentation is available at PropertyReflection.php

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