Packages

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

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

Interfaces

  • IAnnotation
  • Overview
  • Package
  • Class
  • Tree
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://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 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:         $res = array();
 42:         foreach (parent::getParameters() as $param) {
 43:             $res[$param->getName()] = $param->isDefaultValueAvailable()
 44:                 ? $param->getDefaultValue()
 45:                 : NULL;
 46: 
 47:             if ($param->isArray()) {
 48:                 settype($res[$param->getName()], 'array');
 49:             }
 50:         }
 51:         return $res;
 52:     }
 53: 
 54: 
 55: 
 56:     /**
 57:      * Invokes method using named parameters.
 58:      * @param  object
 59:      * @param  array
 60:      * @return mixed
 61:      */
 62:     public function invokeNamedArgs($object, $args)
 63:     {
 64:         $res = array();
 65:         $i = 0;
 66:         foreach ($this->getDefaultParameters() as $name => $def) {
 67:             if (isset($args[$name])) { // NULL treats as none value
 68:                 $val = $args[$name];
 69:                 if ($def !== NULL) {
 70:                     settype($val, gettype($def));
 71:                 }
 72:                 $res[$i++] = $val;
 73:             } else {
 74:                 $res[$i++] = $def;
 75:             }
 76:         }
 77:         return $this->invokeArgs($object, $res);
 78:     }
 79: 
 80: 
 81: 
 82:     /**
 83:      * @return NCallback
 84:      */
 85:     public function getCallback()
 86:     {
 87:         return new NCallback(parent::getDeclaringClass()->getName(), $this->getName());
 88:     }
 89: 
 90: 
 91: 
 92:     public function __toString()
 93:     {
 94:         return 'Method ' . parent::getDeclaringClass()->getName() . '::' . $this->getName() . '()';
 95:     }
 96: 
 97: 
 98: 
 99:     /********************* Reflection layer ****************d*g**/
100: 
101: 
102: 
103:     /**
104:      * @return NClassReflection
105:      */
106:     public function getDeclaringClass()
107:     {
108:         return new NClassReflection(parent::getDeclaringClass()->getName());
109:     }
110: 
111: 
112: 
113:     /**
114:      * @return NExtensionReflection
115:      */
116:     public function getExtension()
117:     {
118:         return ($name = $this->getExtensionName()) ? new NExtensionReflection($name) : NULL;
119:     }
120: 
121: 
122: 
123:     public function getParameters()
124:     {
125:         $me = array(parent::getDeclaringClass()->getName(), $this->getName());
126:         foreach ($res = parent::getParameters() as $key => $val) {
127:             $res[$key] = new NParameterReflection($me, $val->getName());
128:         }
129:         return $res;
130:     }
131: 
132: 
133: 
134:     /********************* NAnnotations support ****************d*g**/
135: 
136: 
137: 
138:     /**
139:      * Has method specified annotation?
140:      * @param  string
141:      * @return bool
142:      */
143:     public function hasAnnotation($name)
144:     {
145:         $res = NAnnotationsParser::getAll($this);
146:         return !empty($res[$name]);
147:     }
148: 
149: 
150: 
151:     /**
152:      * Returns an annotation value.
153:      * @param  string
154:      * @return IAnnotation
155:      */
156:     public function getAnnotation($name)
157:     {
158:         $res = NAnnotationsParser::getAll($this);
159:         return isset($res[$name]) ? end($res[$name]) : NULL;
160:     }
161: 
162: 
163: 
164:     /**
165:      * Returns all annotations.
166:      * @return array
167:      */
168:     public function getAnnotations()
169:     {
170:         return NAnnotationsParser::getAll($this);
171:     }
172: 
173: 
174: 
175:     /********************* NObject behaviour ****************d*g**/
176: 
177: 
178: 
179:     /**
180:      * @return NClassReflection
181:      */
182:     public function getReflection()
183:     {
184:         return new NClassReflection($this);
185:     }
186: 
187: 
188: 
189:     public function __call($name, $args)
190:     {
191:         return NObjectMixin::call($this, $name, $args);
192:     }
193: 
194: 
195: 
196:     public function &__get($name)
197:     {
198:         return NObjectMixin::get($this, $name);
199:     }
200: 
201: 
202: 
203:     public function __set($name, $value)
204:     {
205:         return NObjectMixin::set($this, $name, $value);
206:     }
207: 
208: 
209: 
210:     public function __isset($name)
211:     {
212:         return NObjectMixin::has($this, $name);
213:     }
214: 
215: 
216: 
217:     public function __unset($name)
218:     {
219:         throw new MemberAccessException("Cannot unset the property {$this->reflection->name}::\$$name.");
220:     }
221: 
222: }
223: 
Nette Framework 0.9.7 (for PHP 5.2) API documentation generated by ApiGen 2.3.0