本文整理汇总了PHP中Reflection::getReflectionMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Reflection::getReflectionMethod方法的具体用法?PHP Reflection::getReflectionMethod怎么用?PHP Reflection::getReflectionMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reflection
的用法示例。
在下文中一共展示了Reflection::getReflectionMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMethodRequiredCount
/**
* @param $class
* @param $method
* @return int
*/
public function getMethodRequiredCount($class, $method)
{
if ($this->getCache()->contains(__METHOD__, func_get_args())) {
return $this->getCache()->get(__METHOD__, func_get_args());
}
$requiredCount = 0;
$reflection = Reflection::getReflectionMethod($class, $method);
foreach ($reflection->getParameters() as $parameter) {
if (!$parameter->isDefaultValueAvailable()) {
$requiredCount++;
}
}
$this->getCache()->set(__METHOD__, func_get_args(), $requiredCount);
return $requiredCount;
}
示例2: process
/**
* @param $instance
*/
function process($instance)
{
$class = get_class($instance);
$this->processHook($this->before, $class, $instance);
if (method_exists($instance, 'init')) {
if (in_array('init', $this->getManager()->getInspector()->getPublicMethods($class))) {
$this->getManager()->call($instance, 'init');
} else {
$reflection = Reflection::getReflectionMethod($class, 'init');
$reflection->setAccessible(true);
$this->getManager()->call($instance, 'init');
$reflection->setAccessible(false);
}
}
$this->processHook($this->after, $class, $instance);
}
示例3: launch
/**
* @param null $instance
* @param array $parameters
* @param Manager $manager
* @return mixed
* @throws Exception
*/
function launch($instance = null, $parameters, Manager $manager)
{
$arguments = array();
foreach ($this->arguments as $index => $argument) {
if (is_string($argument) && isset($parameters[$argument])) {
$arguments[] = $parameters[$argument];
} elseif ($argument instanceof Reference) {
// find parameter by class
$foundInParams = false;
foreach ($parameters as $param) {
if (is_a($param, $argument->getClass())) {
$arguments[] = $param;
$foundInParams = true;
break;
}
}
if (!$foundInParams) {
$arguments[] = $argument->getInstance($manager);
}
} else {
if (count(array_filter(array_keys($parameters), 'is_int')) > 0) {
$arguments[] = array_shift($parameters);
} else {
if ($index < $this->requiredCount) {
throw new Exception(sprintf("Key %s for method %s::%s not found!", $argument, $this->class, $this->method));
}
}
}
}
if ($this->method == '__construct') {
if (!count($arguments)) {
return new $this->class();
}
return Reflection::getReflectionClass($this->class)->newInstanceArgs($arguments);
}
if (in_array($this->method, $manager->getInspector()->getPublicMethods($this->class))) {
return call_user_func_array(array($instance, $this->method), $arguments);
}
return Reflection::getReflectionMethod($this->class, $this->method)->invokeArgs($instance, $arguments);
}