Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Diagnostics
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
      • Diagnostics
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • PhpGenerator
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
  • NetteModule
  • none

Classes

  • Annotation
  • AnnotationsParser
  • ClassType
  • Extension
  • GlobalFunction
  • Method
  • Parameter
  • Property

Interfaces

  • IAnnotation
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  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 class.
 16:  *
 17:  * @author     David Grudl
 18:  * @property-read Method $constructor
 19:  * @property-read Extension $extension
 20:  * @property-read ClassType[] $interfaces
 21:  * @property-read Method[] $methods
 22:  * @property-read ClassType $parentClass
 23:  * @property-read Property[] $properties
 24:  * @property-read IAnnotation[][] $annotations
 25:  * @property-read string $description
 26:  * @property-read string $name
 27:  * @property-read bool $internal
 28:  * @property-read bool $userDefined
 29:  * @property-read bool $instantiable
 30:  * @property-read string $fileName
 31:  * @property-read int $startLine
 32:  * @property-read int $endLine
 33:  * @property-read string $docComment
 34:  * @property-read mixed[] $constants
 35:  * @property-read string[] $interfaceNames
 36:  * @property-read bool $interface
 37:  * @property-read bool $abstract
 38:  * @property-read bool $final
 39:  * @property-read int $modifiers
 40:  * @property-read array $staticProperties
 41:  * @property-read array $defaultProperties
 42:  * @property-read bool $iterateable
 43:  * @property-read string $extensionName
 44:  * @property-read string $namespaceName
 45:  * @property-read string $shortName
 46:  */
 47: class ClassType extends \ReflectionClass
 48: {
 49: 
 50: 
 51:     /**
 52:      * @param  string|object
 53:      * @return ClassType
 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:      * @param  string
 69:      * @return bool
 70:      */
 71:     public function is($type)
 72:     {
 73:         return $this->isSubclassOf($type) || strcasecmp($this->getName(), ltrim($type, '\\')) === 0;
 74:     }
 75: 
 76: 
 77:     /********************* Reflection layer ****************d*g**/
 78: 
 79: 
 80:     /**
 81:      * @return Method|NULL
 82:      */
 83:     public function getConstructor()
 84:     {
 85:         return ($ref = parent::getConstructor()) ? Method::from($this->getName(), $ref->getName()) : NULL;
 86:     }
 87: 
 88: 
 89:     /**
 90:      * @return Extension|NULL
 91:      */
 92:     public function getExtension()
 93:     {
 94:         return ($name = $this->getExtensionName()) ? new Extension($name) : NULL;
 95:     }
 96: 
 97: 
 98:     /**
 99:      * @return ClassType[]
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:      * @return Method
113:      */
114:     public function getMethod($name)
115:     {
116:         return new Method($this->getName(), $name);
117:     }
118: 
119: 
120:     /**
121:      * @return Method[]
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:      * @return ClassType|NULL
134:      */
135:     public function getParentClass()
136:     {
137:         return ($ref = parent::getParentClass()) ? new static($ref->getName()) : NULL;
138:     }
139: 
140: 
141:     /**
142:      * @return Property[]
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:      * @return Property
155:      */
156:     public function getProperty($name)
157:     {
158:         return new Property($this->getName(), $name);
159:     }
160: 
161: 
162:     /********************* Nette\Annotations support ****************d*g**/
163: 
164: 
165:     /**
166:      * Has class specified annotation?
167:      * @param  string
168:      * @return bool
169:      */
170:     public function hasAnnotation($name)
171:     {
172:         $res = AnnotationsParser::getAll($this);
173:         return !empty($res[$name]);
174:     }
175: 
176: 
177:     /**
178:      * Returns an annotation value.
179:      * @param  string
180:      * @return IAnnotation
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:      * Returns all annotations.
191:      * @return IAnnotation[][]
192:      */
193:     public function getAnnotations()
194:     {
195:         return AnnotationsParser::getAll($this);
196:     }
197: 
198: 
199:     /**
200:      * Returns value of annotation 'description'.
201:      * @return string
202:      */
203:     public function getDescription()
204:     {
205:         return $this->getAnnotation('description');
206:     }
207: 
208: 
209:     /********************* Nette\Object behaviour ****************d*g**/
210: 
211: 
212:     /**
213:      * @deprecated
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: 
Nette 2.1 API documentation generated by ApiGen 2.8.0