Esempio n. 1
0
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 '';
            }
        }
    }
}
Esempio n. 2
0
 /**
  * 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));
 }
Esempio n. 3
0
 /**
  * @param \ReflectionFunctionAbstract $func
  * @param integer                     $num
  * @return boolean
  */
 public static function matchesNumberOfArguments(\ReflectionFunctionAbstract $func, $num)
 {
     return $func->getNumberOfRequiredParameters() <= $num && $func->getNumberOfParameters() >= $num;
 }