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
  • Deprecated
  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:      * @param  string|object
 58:      * @return NClassReflection
 59:      */
 60:     public static function from($class)
 61:     {
 62:         return new self($class);
 63:     }
 64: 
 65: 
 66:     public function __toString()
 67:     {
 68:         return 'Class ' . $this->getName();
 69:     }
 70: 
 71: 
 72:     /**
 73:      * @return bool
 74:      */
 75:     public function hasEventProperty($name)
 76:     {
 77:         if (preg_match('#^on[A-Z]#', $name) && $this->hasProperty($name)) {
 78:             $rp = $this->getProperty($name);
 79:             return $rp->isPublic() && !$rp->isStatic();
 80:         }
 81:         return FALSE;
 82:     }
 83: 
 84: 
 85:     /**
 86:      * Adds a method to class.
 87:      * @param  string  method name
 88:      * @param  mixed   callable
 89:      * @return self
 90:      */
 91:     public function setExtensionMethod($name, $callback)
 92:     {
 93:         $l = & self::$extMethods[strtolower($name)];
 94:         $l[strtolower($this->getName())] = new NCallback($callback);
 95:         $l[''] = NULL;
 96:         return $this;
 97:     }
 98: 
 99: 
100:     /**
101:      * Returns extension method.
102:      * @param  string  method name
103:      * @return mixed
104:      */
105:     public function getExtensionMethod($name)
106:     {
107:         if (self::$extMethods === NULL || $name === NULL) { // for backwards compatibility
108:             $list = get_defined_functions(); // names are lowercase!
109:             foreach ($list['user'] as $fce) {
110:                 $pair = explode('_prototype_', $fce);
111:                 if (count($pair) === 2) {
112:                     self::$extMethods[$pair[1]][$pair[0]] = new NCallback($fce);
113:                     self::$extMethods[$pair[1]][''] = NULL;
114:                 }
115:             }
116:             if ($name === NULL) {
117:                 return NULL;
118:             }
119:         }
120: 
121:         $class = strtolower($this->getName());
122:         $l = & self::$extMethods[strtolower($name)];
123: 
124:         if (empty($l)) {
125:             return FALSE;
126: 
127:         } elseif (isset($l[''][$class])) { // cached value
128:             return $l[''][$class];
129:         }
130: 
131:         $cl = $class;
132:         do {
133:             if (isset($l[$cl])) {
134:                 return $l[''][$class] = $l[$cl];
135:             }
136:         } while (($cl = strtolower(get_parent_class($cl))) !== '');
137: 
138:         foreach (class_implements($class) as $cl) {
139:             $cl = strtolower($cl);
140:             if (isset($l[$cl])) {
141:                 return $l[''][$class] = $l[$cl];
142:             }
143:         }
144:         return $l[''][$class] = FALSE;
145:     }
146: 
147: 
148:     /**
149:      * @param  string
150:      * @return bool
151:      */
152:     public function is($type)
153:     {
154:         return $this->isSubclassOf($type) || strcasecmp($this->getName(), ltrim($type, '\\')) === 0;
155:     }
156: 
157: 
158:     /********************* Reflection layer ****************d*g**/
159: 
160: 
161:     /**
162:      * @return NMethodReflection|NULL
163:      */
164:     public function getConstructor()
165:     {
166:         return ($ref = parent::getConstructor()) ? NMethodReflection::from($this->getName(), $ref->getName()) : NULL;
167:     }
168: 
169: 
170:     /**
171:      * @return NExtensionReflection|NULL
172:      */
173:     public function getExtension()
174:     {
175:         return ($name = $this->getExtensionName()) ? new NExtensionReflection($name) : NULL;
176:     }
177: 
178: 
179:     /**
180:      * @return NClassReflection[]
181:      */
182:     public function getInterfaces()
183:     {
184:         $res = array();
185:         foreach (parent::getInterfaceNames() as $val) {
186:             $res[$val] = new self($val);
187:         }
188:         return $res;
189:     }
190: 
191: 
192:     /**
193:      * @return NMethodReflection
194:      */
195:     public function getMethod($name)
196:     {
197:         return new NMethodReflection($this->getName(), $name);
198:     }
199: 
200: 
201:     /**
202:      * @return NMethodReflection[]
203:      */
204:     public function getMethods($filter = -1)
205:     {
206:         foreach ($res = parent::getMethods($filter) as $key => $val) {
207:             $res[$key] = new NMethodReflection($this->getName(), $val->getName());
208:         }
209:         return $res;
210:     }
211: 
212: 
213:     /**
214:      * @return NClassReflection|NULL
215:      */
216:     public function getParentClass()
217:     {
218:         return ($ref = parent::getParentClass()) ? new self($ref->getName()) : NULL;
219:     }
220: 
221: 
222:     /**
223:      * @return NPropertyReflection[]
224:      */
225:     public function getProperties($filter = -1)
226:     {
227:         foreach ($res = parent::getProperties($filter) as $key => $val) {
228:             $res[$key] = new NPropertyReflection($this->getName(), $val->getName());
229:         }
230:         return $res;
231:     }
232: 
233: 
234:     /**
235:      * @return NPropertyReflection
236:      */
237:     public function getProperty($name)
238:     {
239:         return new NPropertyReflection($this->getName(), $name);
240:     }
241: 
242: 
243:     /********************* NAnnotations support ****************d*g**/
244: 
245: 
246:     /**
247:      * Has class specified annotation?
248:      * @param  string
249:      * @return bool
250:      */
251:     public function hasAnnotation($name)
252:     {
253:         $res = NAnnotationsParser::getAll($this);
254:         return !empty($res[$name]);
255:     }
256: 
257: 
258:     /**
259:      * Returns an annotation value.
260:      * @param  string
261:      * @return IAnnotation
262:      */
263:     public function getAnnotation($name)
264:     {
265:         $res = NAnnotationsParser::getAll($this);
266:         return isset($res[$name]) ? end($res[$name]) : NULL;
267:     }
268: 
269: 
270:     /**
271:      * Returns all annotations.
272:      * @return IAnnotation[][]
273:      */
274:     public function getAnnotations()
275:     {
276:         return NAnnotationsParser::getAll($this);
277:     }
278: 
279: 
280:     /**
281:      * Returns value of annotation 'description'.
282:      * @return string
283:      */
284:     public function getDescription()
285:     {
286:         return $this->getAnnotation('description');
287:     }
288: 
289: 
290:     /********************* NObject behaviour ****************d*g**/
291: 
292: 
293:     /**
294:      * @return NClassReflection
295:      */
296:     public function getReflection()
297:     {
298:         return new NClassReflection($this);
299:     }
300: 
301: 
302:     public function __call($name, $args)
303:     {
304:         return NObjectMixin::call($this, $name, $args);
305:     }
306: 
307: 
308:     public function &__get($name)
309:     {
310:         return NObjectMixin::get($this, $name);
311:     }
312: 
313: 
314:     public function __set($name, $value)
315:     {
316:         return NObjectMixin::set($this, $name, $value);
317:     }
318: 
319: 
320:     public function __isset($name)
321:     {
322:         return NObjectMixin::has($this, $name);
323:     }
324: 
325: 
326:     public function __unset($name)
327:     {
328:         NObjectMixin::remove($this, $name);
329:     }
330: 
331: }
332: 
Nette Framework 2.0.11 (for PHP 5.2, prefixed) API API documentation generated by ApiGen 2.8.0