Packages

  • Nette
    • Application
      • Application\Diagnostics
      • Application\Responses
      • Application\Routers
      • Application\UI
    • Caching
      • Caching\Storages
    • ComponentModel
    • Config
    • Database
      • Database\Diagnostics
      • Database\Drivers
      • Database\Reflection
      • Database\Table
    • DI
    • Diagnostics
    • Forms
      • Forms\Controls
      • Forms\Rendering
    • Http
    • Iterators
    • Latte
      • Latte\Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • 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, 2011 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 method.
 17:  *
 18:  * @author     David Grudl
 19:  * @package Nette\Reflection
 20:  */
 21: class NMethodReflection extends ReflectionMethod
 22: {
 23: 
 24:     /**
 25:      * @param  string|object
 26:      * @param  string
 27:      * @return NMethodReflection
 28:      */
 29:     public static function from($class, $method)
 30:     {
 31:         return new self(is_object($class) ? get_class($class) : $class, $method);
 32:     }
 33: 
 34: 
 35: 
 36:     /**
 37:      * @return array
 38:      */
 39:     public function getDefaultParameters()
 40:     {
 41:         return self::buildDefaultParameters(parent::getParameters());
 42:     }
 43: 
 44: 
 45: 
 46:     /**
 47:      * Invokes method using named parameters.
 48:      * @param  object
 49:      * @param  array
 50:      * @return mixed
 51:      */
 52:     public function invokeNamedArgs($object, $args)
 53:     {
 54:         return $this->invokeArgs($object, self::combineArgs($this->getDefaultParameters(), $args));
 55:     }
 56: 
 57: 
 58: 
 59:     /**
 60:      * @return NCallback
 61:      */
 62:     public function toCallback()
 63:     {
 64:         return new NCallback(parent::getDeclaringClass()->getName(), $this->getName());
 65:     }
 66: 
 67: 
 68: 
 69:     public function __toString()
 70:     {
 71:         return 'Method ' . parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
 72:     }
 73: 
 74: 
 75: 
 76:     /********************* Reflection layer ****************d*g**/
 77: 
 78: 
 79: 
 80:     /**
 81:      * @return NClassReflection
 82:      */
 83:     public function getDeclaringClass()
 84:     {
 85:         return new NClassReflection(parent::getDeclaringClass()->getName());
 86:     }
 87: 
 88: 
 89: 
 90:     /**
 91:      * @return NMethodReflection
 92:      */
 93:     public function getPrototype()
 94:     {
 95:         $prototype = parent::getPrototype();
 96:         return new NMethodReflection($prototype->getDeclaringClass()->getName(), $prototype->getName());
 97:     }
 98: 
 99: 
100: 
101:     /**
102:      * @return NExtensionReflection
103:      */
104:     public function getExtension()
105:     {
106:         return ($name = $this->getExtensionName()) ? new NExtensionReflection($name) : NULL;
107:     }
108: 
109: 
110: 
111:     public function getParameters()
112:     {
113:         $me = array(parent::getDeclaringClass()->getName(), $this->getName());
114:         foreach ($res = parent::getParameters() as $key => $val) {
115:             $res[$key] = new NParameterReflection($me, $val->getName());
116:         }
117:         return $res;
118:     }
119: 
120: 
121: 
122:     /********************* NAnnotations support ****************d*g**/
123: 
124: 
125: 
126:     /**
127:      * Has method specified annotation?
128:      * @param  string
129:      * @return bool
130:      */
131:     public function hasAnnotation($name)
132:     {
133:         $res = NAnnotationsParser::getAll($this);
134:         return !empty($res[$name]);
135:     }
136: 
137: 
138: 
139:     /**
140:      * Returns an annotation value.
141:      * @param  string
142:      * @return IAnnotation
143:      */
144:     public function getAnnotation($name)
145:     {
146:         $res = NAnnotationsParser::getAll($this);
147:         return isset($res[$name]) ? end($res[$name]) : NULL;
148:     }
149: 
150: 
151: 
152:     /**
153:      * Returns all annotations.
154:      * @return array
155:      */
156:     public function getAnnotations()
157:     {
158:         return NAnnotationsParser::getAll($this);
159:     }
160: 
161: 
162: 
163:     /**
164:      * Returns value of annotation 'description'.
165:      * @return string
166:      */
167:     public function getDescription()
168:     {
169:         return $this->getAnnotation('description');
170:     }
171: 
172: 
173: 
174:     /********************* NObject behaviour ****************d*g**/
175: 
176: 
177: 
178:     /**
179:      * @return NClassReflection
180:      */
181:     public function getReflection()
182:     {
183:         return new NClassReflection($this);
184:     }
185: 
186: 
187: 
188:     public function __call($name, $args)
189:     {
190:         return NObjectMixin::call($this, $name, $args);
191:     }
192: 
193: 
194: 
195:     public function &__get($name)
196:     {
197:         return NObjectMixin::get($this, $name);
198:     }
199: 
200: 
201: 
202:     public function __set($name, $value)
203:     {
204:         return NObjectMixin::set($this, $name, $value);
205:     }
206: 
207: 
208: 
209:     public function __isset($name)
210:     {
211:         return NObjectMixin::has($this, $name);
212:     }
213: 
214: 
215: 
216:     public function __unset($name)
217:     {
218:         NObjectMixin::remove($this, $name);
219:     }
220: 
221: 
222: 
223:     /********************* helpers ****************d*g**/
224: 
225: 
226: 
227:     /** @internal */
228:     public static function buildDefaultParameters($params)
229:     {
230:         $res = array();
231:         foreach ($params as $param) {
232:             $res[$param->getName()] = $param->isDefaultValueAvailable()
233:                 ? $param->getDefaultValue()
234:                 : NULL;
235: 
236:             if ($param->isArray()) {
237:                 settype($res[$param->getName()], 'array');
238:             }
239:         }
240:         return $res;
241:     }
242: 
243: 
244: 
245:     /** @internal */
246:     public static function combineArgs($params, $args)
247:     {
248:         $res = array();
249:         $i = 0;
250:         foreach ($params as $name => $def) {
251:             if (isset($args[$name])) { // NULL treats as none value
252:                 $val = $args[$name];
253:                 if ($def !== NULL) {
254:                     settype($val, gettype($def));
255:                 }
256:                 $res[$i++] = $val;
257:             } else {
258:                 $res[$i++] = $def;
259:             }
260:         }
261:         return $res;
262:     }
263: 
264: }
265: 
Nette Framework 2.0beta1 (for PHP 5.2) API API documentation generated by ApiGen 2.3.0