本文整理汇总了PHP中ReflectionFunctionAbstract::getNumberOfParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunctionAbstract::getNumberOfParameters方法的具体用法?PHP ReflectionFunctionAbstract::getNumberOfParameters怎么用?PHP ReflectionFunctionAbstract::getNumberOfParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunctionAbstract
的用法示例。
在下文中一共展示了ReflectionFunctionAbstract::getNumberOfParameters方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadArguments
/**
* Populates arguments assembled from the event and the given target function.
*
* @param \ReflectionFunctionAbstract $ref
* @param EventParamResolverInterface $resolver
* @return array
*/
protected function loadArguments(\ReflectionFunctionAbstract $ref, EventParamResolverInterface $resolver)
{
$args = [];
if ($ref->getNumberOfParameters() > 1) {
foreach (array_slice($ref->getParameters(), 1) as $param) {
$args[] = $resolver->resolve($param->getClass(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : false);
}
}
return $args;
}
示例2: resolve
/**
* Resolves function arguments.
*
* @param array $parameters
*
* @return array
*
* @throws UnresolvableArgumentException
*/
public function resolve(array $parameters)
{
if (!($number = $this->reflection->getNumberOfParameters())) {
return [];
}
$arguments = array_fill(0, $number, null);
foreach ($this->getParameters() as $pos => $parameter) {
$result = $this->match($parameter, $parameters);
if ($result) {
$arguments[$pos] = $result[1];
unset($parameters[$result[0]]);
continue;
}
if ($parameter->isDefaultValueAvailable()) {
$arguments[$pos] = $parameter->getDefaultValue();
continue;
}
throw new UnresolvableArgumentException($parameter);
}
return $arguments;
}
示例3: normalizeParams
/**
* normalize the params of the $rmethod to allow a valid call
*
* @example
* // method signature: foo($bar = '',$baz = '',SomeClass $che);
* $rmethod = new ReflectionMethod($instance,'foo');
* $this->normalizeParams($rmethod,array('che','cha')) // retuns array('che','cha',automatically created SomeClass Instance)
* $this->normalizeParams($rmethod,array('che')) // retuns array('che','',automatically created SomeClass Instance)
* $this->normalizeParams($rmethod,array('che' => new SomeClass(),'bar' => '')) // retuns array('','',passed in SomeClass Instance)
*
* @param ReflectionFunctionAbstract $rfunc the reflection of the method/function
* @param array $params any params you want to pass to override any magically
* discovered params
* @return array the params ready to be passed to the method using something like call_user_func_array
*/
public function normalizeParams(\ReflectionFunctionAbstract $rfunc, array $params = array())
{
// canary...
if ($rfunc->getNumberOfParameters() <= 0) {
return $params;
}
//if
$ret_params = array();
$rparams = $rfunc->getParameters();
foreach ($rparams as $rparam) {
$ret_params[] = $this->normalizeParam($rparam, $params);
}
//foreach
return $ret_params;
}
示例4: makeFunctionSignature
/**
* Create a string representation of the method signature.
*
* @param ReflectionFunctionAbstract $func The function you want a signature for.
* @return void
**/
public static function makeFunctionSignature(ReflectionFunctionAbstract $func)
{
$signature = $func->getName() . '( ';
foreach ($func->getParameters() as $param) {
$signature .= '$' . $param->getName();
if ($param->isDefaultValueAvailable()) {
$signature .= ' = ' . var_export($param->getDefaultValue(), true);
}
$signature .= ', ';
}
if ($func->getNumberOfParameters() > 0) {
$signature = substr($signature, 0, -2);
}
$signature .= ' )';
return $signature;
}
示例5: hashParameters
private static function hashParameters(\ReflectionFunctionAbstract $method)
{
$res = [];
if (PHP_VERSION_ID < 70000 && $method->getNumberOfParameters() && $method->getFileName()) {
$res[] = file($method->getFileName())[$method->getStartLine() - 1];
}
foreach ($method->getParameters() as $param) {
$res[] = [$param->getName(), PHP_VERSION_ID >= 70000 ? PhpReflection::getParameterType($param) : NULL, $param->isVariadic(), $param->isDefaultValueAvailable() ? $param->isDefaultValueConstant() ? $param->getDefaultValueConstantName() : [$param->getDefaultValue()] : NULL];
}
return $res;
}
示例6: matchesNumberOfArguments
/**
* @param \ReflectionFunctionAbstract $func
* @param integer $num
* @return boolean
*/
public static function matchesNumberOfArguments(\ReflectionFunctionAbstract $func, $num)
{
return $func->getNumberOfRequiredParameters() <= $num && $func->getNumberOfParameters() >= $num;
}