本文整理汇总了PHP中ReflectionFunctionAbstract::getNumberOfRequiredParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunctionAbstract::getNumberOfRequiredParameters方法的具体用法?PHP ReflectionFunctionAbstract::getNumberOfRequiredParameters怎么用?PHP ReflectionFunctionAbstract::getNumberOfRequiredParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunctionAbstract
的用法示例。
在下文中一共展示了ReflectionFunctionAbstract::getNumberOfRequiredParameters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatSignature
function formatSignature(\ReflectionFunctionAbstract $refl, $arg = -1)
{
$params = $refl->getParameters();
$n = $refl->getNumberOfRequiredParameters();
$required = array_slice($params, 0, $n);
$optional = array_slice($params, $n);
if (count($optional) && count($required)) {
return sprintf('%s[, %s]', formatParams($required, $arg), formatParams($optional, $arg));
} else {
if (count($required)) {
return formatParams($required, $arg);
} else {
if (count($optional)) {
return sprintf('[%s]', formatParams($optional, $arg));
} else {
return '';
}
}
}
}
示例2: resolveParams
/**
* Resolve callable params
*
* @param ReflectionMethod $reflectionCallable
* @param array $params
*
* @return array
*/
private function resolveParams(\ReflectionFunctionAbstract $reflectionCallable, array $params)
{
if ($reflectionCallable->getNumberOfRequiredParameters() > count($params)) {
throw new \LogicException(sprintf('callable has %d required parameters but %d provided.', $reflectionCallable->getNumberOfRequiredParameters(), count($params)));
}
$self = $this;
return array_map(function ($paramTuple) use($self) {
list($relfectionParam, $param) = $paramTuple;
// TODO : refactor
if ($relfectionParam->isDefaultValueAvailable() && $param === $relfectionParam->getDefaultValue()) {
return $param;
}
$isClassHinted = null !== ($classHint = $relfectionParam->getClass());
return $isClassHinted && !is_object($param) ? $self->instantiateObject($classHint, (array) $param) : $param;
}, $this->pair($reflectionCallable->getParameters(), $params));
}
示例3: matchesNumberOfArguments
/**
* @param \ReflectionFunctionAbstract $func
* @param integer $num
* @return boolean
*/
public static function matchesNumberOfArguments(\ReflectionFunctionAbstract $func, $num)
{
return $func->getNumberOfRequiredParameters() <= $num && $func->getNumberOfParameters() >= $num;
}