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

Classes

Interfaces

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