Packages

  • 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
  • PHP

Classes

  • NAnnotation
  • NAnnotationsParser
  • NClassReflection
  • NExtensionReflection
  • NFunctionReflection
  • NMethodReflection
  • NParameterReflection
  • NPropertyReflection

Interfaces

  • IAnnotation
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Reflection
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Reports information about a class.
 17:  *
 18:  * @author     David Grudl
 19:  * @property-read NMethodReflection $constructor
 20:  * @property-read NExtensionReflection $extension
 21:  * @property-read NClassReflection[] $interfaces
 22:  * @property-read NMethodReflection[] $methods
 23:  * @property-read NClassReflection $parentClass
 24:  * @property-read NPropertyReflection[] $properties
 25:  * @property-read IAnnotation[][] $annotations
 26:  * @property-read string $description
 27:  * @property-read string $name
 28:  * @property-read bool $internal
 29:  * @property-read bool $userDefined
 30:  * @property-read bool $instantiable
 31:  * @property-read string $fileName
 32:  * @property-read int $startLine
 33:  * @property-read int $endLine
 34:  * @property-read string $docComment
 35:  * @property-read mixed[] $constants
 36:  * @property-read string[] $interfaceNames
 37:  * @property-read bool $interface
 38:  * @property-read bool $abstract
 39:  * @property-read bool $final
 40:  * @property-read int $modifiers
 41:  * @property-read array $staticProperties
 42:  * @property-read array $defaultProperties
 43:  * @property-read bool $iterateable
 44:  * @property-read string $extensionName
 45:  * @property-read string $namespaceName
 46:  * @property-read string $shortName
 47:  * @package Nette\Reflection
 48:  */
 49: class NClassReflection extends ReflectionClass
 50: {
 51: 
 52:     /** @var array (method => array(type => callable)) */
 53:     private static $extMethods;
 54: 
 55: 
 56: 
 57:     /**
 58:      * @param  string|object
 59:      * @return NClassReflection
 60:      */
 61:     public static function from($class)
 62:     {
 63:         return new self($class);
 64:     }
 65: 
 66: 
 67: 
 68:     public function __toString()
 69:     {
 70:         return 'Class ' . $this->getName();
 71:     }
 72: 
 73: 
 74: 
 75:     /**
 76:      * @return bool
 77:      */
 78:     public function hasEventProperty($name)
 79:     {
 80:         if (preg_match('#^on[A-Z]#', $name) && $this->hasProperty($name)) {
 81:             $rp = $this->getProperty($name);
 82:             return $rp->isPublic() && !$rp->isStatic();
 83:         }
 84:         return FALSE;
 85:     }
 86: 
 87: 
 88: 
 89:     /**
 90:      * Adds a method to class.
 91:      * @param  string  method name
 92:      * @param  mixed   callable
 93:      * @return NClassReflection  provides a fluent interface
 94:      */
 95:     public function setExtensionMethod($name, $callback)
 96:     {
 97:         $l = & self::$extMethods[strtolower($name)];
 98:         $l[strtolower($this->getName())] = callback($callback);
 99:         $l[''] = NULL;
100:         return $this;
101:     }
102: 
103: 
104: 
105:     /**
106:      * Returns extension method.
107:      * @param  string  method name
108:      * @return mixed
109:      */
110:     public function getExtensionMethod($name)
111:     {
112:         if (self::$extMethods === NULL || $name === NULL) { // for backwards compatibility
113:             $list = get_defined_functions(); // names are lowercase!
114:             foreach ($list['user'] as $fce) {
115:                 $pair = explode('_prototype_', $fce);
116:                 if (count($pair) === 2) {
117:                     self::$extMethods[$pair[1]][$pair[0]] = callback($fce);
118:                     self::$extMethods[$pair[1]][''] = NULL;
119:                 }
120:             }
121:             if ($name === NULL) {
122:                 return NULL;
123:             }
124:         }
125: 
126:         $class = strtolower($this->getName());
127:         $l = & self::$extMethods[strtolower($name)];
128: 
129:         if (empty($l)) {
130:             return FALSE;
131: 
132:         } elseif (isset($l[''][$class])) { // cached value
133:             return $l[''][$class];
134:         }
135: 
136:         $cl = $class;
137:         do {
138:             if (isset($l[$cl])) {
139:                 return $l[''][$class] = $l[$cl];
140:             }
141:         } while (($cl = strtolower(get_parent_class($cl))) !== '');
142: 
143:         foreach (class_implements($class) as $cl) {
144:             $cl = strtolower($cl);
145:             if (isset($l[$cl])) {
146:                 return $l[''][$class] = $l[$cl];
147:             }
148:         }
149:         return $l[''][$class] = FALSE;
150:     }
151: 
152: 
153: 
154:     /**
155:      * @param  string
156:      * @return bool
157:      */
158:     public function is($type)
159:     {
160:         return $this->isSubclassOf($type) || strcasecmp($this->getName(), ltrim($type, '\\')) === 0;
161:     }
162: 
163: 
164: 
165:     /********************* Reflection layer ****************d*g**/
166: 
167: 
168: 
169:     /**
170:      * @return NMethodReflection|NULL
171:      */
172:     public function getConstructor()
173:     {
174:         return ($ref = parent::getConstructor()) ? NMethodReflection::from($this->getName(), $ref->getName()) : NULL;
175:     }
176: 
177: 
178: 
179:     /**
180:      * @return NExtensionReflection|NULL
181:      */
182:     public function getExtension()
183:     {
184:         return ($name = $this->getExtensionName()) ? new NExtensionReflection($name) : NULL;
185:     }
186: 
187: 
188: 
189:     /**
190:      * @return NClassReflection[]
191:      */
192:     public function getInterfaces()
193:     {
194:         $res = array();
195:         foreach (parent::getInterfaceNames() as $val) {
196:             $res[$val] = new self($val);
197:         }
198:         return $res;
199:     }
200: 
201: 
202: 
203:     /**
204:      * @return NMethodReflection
205:      */
206:     public function getMethod($name)
207:     {
208:         return new NMethodReflection($this->getName(), $name);
209:     }
210: 
211: 
212:     /**
213:      * @return NMethodReflection[]
214:      */
215:     public function getMethods($filter = -1)
216:     {
217:         foreach ($res = parent::getMethods($filter) as $key => $val) {
218:             $res[$key] = new NMethodReflection($this->getName(), $val->getName());
219:         }
220:         return $res;
221:     }
222: 
223: 
224: 
225:     /**
226:      * @return NClassReflection|NULL
227:      */
228:     public function getParentClass()
229:     {
230:         return ($ref = parent::getParentClass()) ? new self($ref->getName()) : NULL;
231:     }
232: 
233: 
234:     /**
235:      * @return NPropertyReflection[]
236:      */
237:     public function getProperties($filter = -1)
238:     {
239:         foreach ($res = parent::getProperties($filter) as $key => $val) {
240:             $res[$key] = new NPropertyReflection($this->getName(), $val->getName());
241:         }
242:         return $res;
243:     }
244: 
245: 
246: 
247:     /**
248:      * @return NPropertyReflection
249:      */
250:     public function getProperty($name)
251:     {
252:         return new NPropertyReflection($this->getName(), $name);
253:     }
254: 
255: 
256: 
257:     /********************* NAnnotations support ****************d*g**/
258: 
259: 
260: 
261:     /**
262:      * Has class specified annotation?
263:      * @param  string
264:      * @return bool
265:      */
266:     public function hasAnnotation($name)
267:     {
268:         $res = NAnnotationsParser::getAll($this);
269:         return !empty($res[$name]);
270:     }
271: 
272: 
273: 
274:     /**
275:      * Returns an annotation value.
276:      * @param  string
277:      * @return IAnnotation
278:      */
279:     public function getAnnotation($name)
280:     {
281:         $res = NAnnotationsParser::getAll($this);
282:         return isset($res[$name]) ? end($res[$name]) : NULL;
283:     }
284: 
285: 
286: 
287:     /**
288:      * Returns all annotations.
289:      * @return IAnnotation[][]
290:      */
291:     public function getAnnotations()
292:     {
293:         return NAnnotationsParser::getAll($this);
294:     }
295: 
296: 
297: 
298:     /**
299:      * Returns value of annotation 'description'.
300:      * @return string
301:      */
302:     public function getDescription()
303:     {
304:         return $this->getAnnotation('description');
305:     }
306: 
307: 
308: 
309:     /********************* NObject behaviour ****************d*g**/
310: 
311: 
312: 
313:     /**
314:      * @return NClassReflection
315:      */
316:     public function getReflection()
317:     {
318:         return new NClassReflection($this);
319:     }
320: 
321: 
322: 
323:     public function __call($name, $args)
324:     {
325:         return NObjectMixin::call($this, $name, $args);
326:     }
327: 
328: 
329: 
330:     public function &__get($name)
331:     {
332:         return NObjectMixin::get($this, $name);
333:     }
334: 
335: 
336: 
337:     public function __set($name, $value)
338:     {
339:         return NObjectMixin::set($this, $name, $value);
340:     }
341: 
342: 
343: 
344:     public function __isset($name)
345:     {
346:         return NObjectMixin::has($this, $name);
347:     }
348: 
349: 
350: 
351:     public function __unset($name)
352:     {
353:         NObjectMixin::remove($this, $name);
354:     }
355: 
356: }
357: 
Nette Framework 2.0.4 (for PHP 5.2, prefixed) API API documentation generated by ApiGen 2.7.0