Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • 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 (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Reflection;
  9: 
 10: use Nette,
 11:     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:     /** @var array (method => array(type => callable)) */
 51:     private static $extMethods;
 52: 
 53: 
 54:     /**
 55:      * @param  string|object
 56:      * @return ClassType
 57:      */
 58:     public static function from($class)
 59:     {
 60:         return new static($class);
 61:     }
 62: 
 63: 
 64:     public function __toString()
 65:     {
 66:         return 'Class ' . $this->getName();
 67:     }
 68: 
 69: 
 70:     /**
 71:      * @return bool
 72:      */
 73:     public function hasEventProperty($name)
 74:     {
 75:         if (preg_match('#^on[A-Z]#', $name) && $this->hasProperty($name)) {
 76:             $rp = $this->getProperty($name);
 77:             return $rp->isPublic() && !$rp->isStatic();
 78:         }
 79:         return FALSE;
 80:     }
 81: 
 82: 
 83:     /**
 84:      * Adds a method to class.
 85:      * @param  string  method name
 86:      * @param  mixed   callable
 87:      * @return self
 88:      */
 89:     public function setExtensionMethod($name, $callback)
 90:     {
 91:         $l = & self::$extMethods[strtolower($name)];
 92:         $l[strtolower($this->getName())] = new Nette\Callback($callback);
 93:         $l[''] = NULL;
 94:         return $this;
 95:     }
 96: 
 97: 
 98:     /**
 99:      * Returns extension method.
100:      * @param  string  method name
101:      * @return mixed
102:      */
103:     public function getExtensionMethod($name)
104:     {
105:         $class = strtolower($this->getName());
106:         $l = & self::$extMethods[strtolower($name)];
107: 
108:         if (empty($l)) {
109:             return FALSE;
110: 
111:         } elseif (isset($l[''][$class])) { // cached value
112:             return $l[''][$class];
113:         }
114: 
115:         $cl = $class;
116:         do {
117:             if (isset($l[$cl])) {
118:                 return $l[''][$class] = $l[$cl];
119:             }
120:         } while (($cl = strtolower(get_parent_class($cl))) !== '');
121: 
122:         foreach (class_implements($class) as $cl) {
123:             $cl = strtolower($cl);
124:             if (isset($l[$cl])) {
125:                 return $l[''][$class] = $l[$cl];
126:             }
127:         }
128:         return $l[''][$class] = FALSE;
129:     }
130: 
131: 
132:     /**
133:      * @param  string
134:      * @return bool
135:      */
136:     public function is($type)
137:     {
138:         return $this->isSubclassOf($type) || strcasecmp($this->getName(), ltrim($type, '\\')) === 0;
139:     }
140: 
141: 
142:     /********************* Reflection layer ****************d*g**/
143: 
144: 
145:     /**
146:      * @return Method|NULL
147:      */
148:     public function getConstructor()
149:     {
150:         return ($ref = parent::getConstructor()) ? Method::from($this->getName(), $ref->getName()) : NULL;
151:     }
152: 
153: 
154:     /**
155:      * @return Extension|NULL
156:      */
157:     public function getExtension()
158:     {
159:         return ($name = $this->getExtensionName()) ? new Extension($name) : NULL;
160:     }
161: 
162: 
163:     /**
164:      * @return ClassType[]
165:      */
166:     public function getInterfaces()
167:     {
168:         $res = array();
169:         foreach (parent::getInterfaceNames() as $val) {
170:             $res[$val] = new static($val);
171:         }
172:         return $res;
173:     }
174: 
175: 
176:     /**
177:      * @return Method
178:      */
179:     public function getMethod($name)
180:     {
181:         return new Method($this->getName(), $name);
182:     }
183: 
184: 
185:     /**
186:      * @return Method[]
187:      */
188:     public function getMethods($filter = -1)
189:     {
190:         foreach ($res = parent::getMethods($filter) as $key => $val) {
191:             $res[$key] = new Method($this->getName(), $val->getName());
192:         }
193:         return $res;
194:     }
195: 
196: 
197:     /**
198:      * @return ClassType|NULL
199:      */
200:     public function getParentClass()
201:     {
202:         return ($ref = parent::getParentClass()) ? new static($ref->getName()) : NULL;
203:     }
204: 
205: 
206:     /**
207:      * @return Property[]
208:      */
209:     public function getProperties($filter = -1)
210:     {
211:         foreach ($res = parent::getProperties($filter) as $key => $val) {
212:             $res[$key] = new Property($this->getName(), $val->getName());
213:         }
214:         return $res;
215:     }
216: 
217: 
218:     /**
219:      * @return Property
220:      */
221:     public function getProperty($name)
222:     {
223:         return new Property($this->getName(), $name);
224:     }
225: 
226: 
227:     /********************* Nette\Annotations support ****************d*g**/
228: 
229: 
230:     /**
231:      * Has class specified annotation?
232:      * @param  string
233:      * @return bool
234:      */
235:     public function hasAnnotation($name)
236:     {
237:         $res = AnnotationsParser::getAll($this);
238:         return !empty($res[$name]);
239:     }
240: 
241: 
242:     /**
243:      * Returns an annotation value.
244:      * @param  string
245:      * @return IAnnotation
246:      */
247:     public function getAnnotation($name)
248:     {
249:         $res = AnnotationsParser::getAll($this);
250:         return isset($res[$name]) ? end($res[$name]) : NULL;
251:     }
252: 
253: 
254:     /**
255:      * Returns all annotations.
256:      * @return IAnnotation[][]
257:      */
258:     public function getAnnotations()
259:     {
260:         return AnnotationsParser::getAll($this);
261:     }
262: 
263: 
264:     /**
265:      * Returns value of annotation 'description'.
266:      * @return string
267:      */
268:     public function getDescription()
269:     {
270:         return $this->getAnnotation('description');
271:     }
272: 
273: 
274:     /********************* Nette\Object behaviour ****************d*g**/
275: 
276: 
277:     /**
278:      * @return ClassType
279:      */
280:     public static function getReflection()
281:     {
282:         return new ClassType(get_called_class());
283:     }
284: 
285: 
286:     public function __call($name, $args)
287:     {
288:         return ObjectMixin::call($this, $name, $args);
289:     }
290: 
291: 
292:     public function &__get($name)
293:     {
294:         return ObjectMixin::get($this, $name);
295:     }
296: 
297: 
298:     public function __set($name, $value)
299:     {
300:         ObjectMixin::set($this, $name, $value);
301:     }
302: 
303: 
304:     public function __isset($name)
305:     {
306:         return ObjectMixin::has($this, $name);
307:     }
308: 
309: 
310:     public function __unset($name)
311:     {
312:         ObjectMixin::remove($this, $name);
313:     }
314: 
315: }
316: 
Nette 2.0 API documentation generated by ApiGen 2.8.0