/** * @return MethodReflection | FunctionReflection */ public function getDeclaringFunction() { return ($ref = parent::getDeclaringFunction()) instanceof ReflectionMethod ? MethodReflection::import($ref) : FunctionReflection::import($ref); }
/** * Is a method callable? It means class is instantiable and method has * public visibility, is non-static and non-abstract. * @param string method name * @return bool */ public function hasCallableMethod($method) { $class = $this->getName(); $cache =& self::$mcCache[strtolower($class . ':' . $method)]; if ($cache === NULL) { try { $cache = FALSE; $rm = MethodReflection::from($class, $method); $cache = $this->isInstantiable() && $rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic(); } catch (ReflectionException $e) { } } return $cache; }
/** * Converts list of arguments to named parameters. * @param string class name * @param string method name * @param array arguments * @param array supplemental arguments * @return void * @throws InvalidLinkException */ private static function argsToParams($class, $method, &$args, $supplemental = array()) { static $cache; $params =& $cache[strtolower($class . ':' . $method)]; if ($params === NULL) { $params = MethodReflection::from($class, $method)->getDefaultParameters(); } $i = 0; foreach ($params as $name => $def) { if (array_key_exists($i, $args)) { $args[$name] = $args[$i]; unset($args[$i]); $i++; } elseif (array_key_exists($name, $args)) { // continue with process } elseif (array_key_exists($name, $supplemental)) { $args[$name] = $supplemental[$name]; } else { continue; } if ($def === NULL) { if ((string) $args[$name] === '') { $args[$name] = NULL; } // value transmit is unnecessary } else { settype($args[$name], gettype($def)); if ($args[$name] === $def) { $args[$name] = NULL; } } } if (array_key_exists($i, $args)) { throw new InvalidLinkException("Extra parameter for signal '{$class}:{$method}'."); } }
/** * @return MethodReflection */ public function getConstructor() { return ($ref = parent::getConstructor()) ? MethodReflection::import($ref) : NULL; }
/** * @return MethodReflection */ public function getMethod($name) { return MethodReflection::import(parent::getMethod($name)); }
public function testGetTypeReflections() { $reflectedMethod = new MethodReflection('TRex\\Reflection\\resources\\Foo', 'getBar'); $this->assertCount(2, $reflectedMethod->getTypeReflections()); $this->assertInstanceOf('TRex\\Reflection\\TypeReflection', $reflectedMethod->getTypeReflections()[0]); $this->assertSame(TypeReflection::STRING_TYPE, $reflectedMethod->getTypeReflections()[0]->getStandardizedType()); $this->assertInstanceOf('TRex\\Reflection\\TypeReflection', $reflectedMethod->getTypeReflections()[1]); $this->assertSame(TypeReflection::NULL_TYPE, $reflectedMethod->getTypeReflections()[1]->getStandardizedType()); }
/** * @return MethodReflection|NULL */ public function getConstructor() { return ($ref = parent::getConstructor()) ? MethodReflection::from($this->getName(), $ref->getName()) : NULL; }