Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Annotation
  • AnnotationsParser
  • ClassType
  • Extension
  • GlobalFunction
  • Helpers
  • 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\Utils\ObjectMixin;
 12: 
 13: 
 14: /**
 15:  * Reports information about a class.
 16:  * @property-read Method $constructor
 17:  * @property-read Extension $extension
 18:  * @property-read ClassType[] $interfaces
 19:  * @property-read Method[] $methods
 20:  * @property-read ClassType $parentClass
 21:  * @property-read Property[] $properties
 22:  * @property-read IAnnotation[][] $annotations
 23:  * @property-read string $description
 24:  * @property-read string $name
 25:  * @property-read bool $internal
 26:  * @property-read bool $userDefined
 27:  * @property-read bool $instantiable
 28:  * @property-read string $fileName
 29:  * @property-read int $startLine
 30:  * @property-read int $endLine
 31:  * @property-read string $docComment
 32:  * @property-read mixed[] $constants
 33:  * @property-read string[] $interfaceNames
 34:  * @property-read bool $interface
 35:  * @property-read bool $abstract
 36:  * @property-read bool $final
 37:  * @property-read int $modifiers
 38:  * @property-read array $staticProperties
 39:  * @property-read array $defaultProperties
 40:  * @property-read bool $iterateable
 41:  * @property-read string $extensionName
 42:  * @property-read string $namespaceName
 43:  * @property-read string $shortName
 44:  */
 45: class ClassType extends \ReflectionClass
 46: {
 47: 
 48: 
 49:     /**
 50:      * @param  string|object
 51:      * @return self
 52:      */
 53:     public static function from($class)
 54:     {
 55:         return new static($class);
 56:     }
 57: 
 58: 
 59:     public function __toString()
 60:     {
 61:         return $this->getName();
 62:     }
 63: 
 64: 
 65:     /**
 66:      * @param  string
 67:      * @return bool
 68:      */
 69:     public function is($type)
 70:     {
 71:         return $this->isSubclassOf($type) || strcasecmp($this->getName(), ltrim($type, '\\')) === 0;
 72:     }
 73: 
 74: 
 75:     /********************* Reflection layer ****************d*g**/
 76: 
 77: 
 78:     /**
 79:      * @return Method|NULL
 80:      */
 81:     public function getConstructor()
 82:     {
 83:         return ($ref = parent::getConstructor()) ? Method::from($this->getName(), $ref->getName()) : NULL;
 84:     }
 85: 
 86: 
 87:     /**
 88:      * @return Extension|NULL
 89:      */
 90:     public function getExtension()
 91:     {
 92:         return ($name = $this->getExtensionName()) ? new Extension($name) : NULL;
 93:     }
 94: 
 95: 
 96:     /**
 97:      * @return self[]
 98:      */
 99:     public function getInterfaces()
100:     {
101:         $res = array();
102:         foreach (parent::getInterfaceNames() as $val) {
103:             $res[$val] = new static($val);
104:         }
105:         return $res;
106:     }
107: 
108: 
109:     /**
110:      * @return Method
111:      */
112:     public function getMethod($name)
113:     {
114:         return new Method($this->getName(), $name);
115:     }
116: 
117: 
118:     /**
119:      * @return Method[]
120:      */
121:     public function getMethods($filter = -1)
122:     {
123:         foreach ($res = parent::getMethods($filter) as $key => $val) {
124:             $res[$key] = new Method($this->getName(), $val->getName());
125:         }
126:         return $res;
127:     }
128: 
129: 
130:     /**
131:      * @return self|NULL
132:      */
133:     public function getParentClass()
134:     {
135:         return ($ref = parent::getParentClass()) ? new static($ref->getName()) : NULL;
136:     }
137: 
138: 
139:     /**
140:      * @return Property[]
141:      */
142:     public function getProperties($filter = -1)
143:     {
144:         foreach ($res = parent::getProperties($filter) as $key => $val) {
145:             $res[$key] = new Property($this->getName(), $val->getName());
146:         }
147:         return $res;
148:     }
149: 
150: 
151:     /**
152:      * @return Property
153:      */
154:     public function getProperty($name)
155:     {
156:         return new Property($this->getName(), $name);
157:     }
158: 
159: 
160:     /********************* Nette\Annotations support ****************d*g**/
161: 
162: 
163:     /**
164:      * Has class specified annotation?
165:      * @param  string
166:      * @return bool
167:      */
168:     public function hasAnnotation($name)
169:     {
170:         $res = AnnotationsParser::getAll($this);
171:         return !empty($res[$name]);
172:     }
173: 
174: 
175:     /**
176:      * Returns an annotation value.
177:      * @param  string
178:      * @return IAnnotation
179:      */
180:     public function getAnnotation($name)
181:     {
182:         $res = AnnotationsParser::getAll($this);
183:         return isset($res[$name]) ? end($res[$name]) : NULL;
184:     }
185: 
186: 
187:     /**
188:      * Returns all annotations.
189:      * @return IAnnotation[][]
190:      */
191:     public function getAnnotations()
192:     {
193:         return AnnotationsParser::getAll($this);
194:     }
195: 
196: 
197:     /**
198:      * Returns value of annotation 'description'.
199:      * @return string
200:      */
201:     public function getDescription()
202:     {
203:         return $this->getAnnotation('description');
204:     }
205: 
206: 
207:     /********************* Nette\Object behaviour ****************d*g**/
208: 
209: 
210:     public function __call($name, $args)
211:     {
212:         return ObjectMixin::call($this, $name, $args);
213:     }
214: 
215: 
216:     public function &__get($name)
217:     {
218:         return ObjectMixin::get($this, $name);
219:     }
220: 
221: 
222:     public function __set($name, $value)
223:     {
224:         ObjectMixin::set($this, $name, $value);
225:     }
226: 
227: 
228:     public function __isset($name)
229:     {
230:         return ObjectMixin::has($this, $name);
231:     }
232: 
233: 
234:     public function __unset($name)
235:     {
236:         ObjectMixin::remove($this, $name);
237:     }
238: 
239: }
240: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0