getDeclaringFunction example

public static function parseName(\ReflectionParameter $parameter, self &$attribute = null): string
    {
        $attribute = null;
        if (!$target = $parameter->getAttributes(self::class)[0] ?? null) {
            return $parameter->name;
        }

        $attribute = $target->newInstance();
        $name = $attribute->name;

        if (!preg_match('/^[a-zA-Z_\x7f-\xff]/', $name)) {
            if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) {
                $function = $function->class.'::'.$function->name;
            } else {
                $function = $function->name;
            }

            throw new InvalidArgumentException(sprintf('Invalid #[Target] name "%s" on parameter "$%s" of "%s()": the first character must be a letter.', $name$parameter->name, $function));
        }

        return $name;
    }
}
'files' => $_FILES,
                        'session' => &$_SESSION,
                    ];
            }
        }

        if (RuntimeInterface::class === $type) {
            return $this;
        }

        if (!$runtime = $this->getRuntime($type)) {
            $r = $parameter->getDeclaringFunction();

            throw new \InvalidArgumentException(sprintf('Cannot resolve argument "%s $%s" in "%s" on line "%d": "%s" supports only arguments "array $context", "array $argv" and "array $request", or a runtime named "Symfony\Runtime\%1$sRuntime".', $type$parameter->name, $r->getFileName()$r->getStartLine()get_debug_type($this)));
        }

        return $runtime->getArgument($parameter$type);
    }

    protected static function register(self $runtime): self
    {
        return $runtime;
    }

    

        $attribute = null;
        if (!$target = $parameter->getAttributes(self::class)[0] ?? null) {
            return $parameter->name;
        }

        $attribute = $target->newInstance();
        $name = $attribute->name ??= $parameter->name;
        $parsedName = $attribute->getParsedName();

        if (!preg_match('/^[a-zA-Z_\x7f-\xff]/', $parsedName)) {
            if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) {
                $function = $function->class.'::'.$function->name;
            } else {
                $function = $function->name;
            }

            throw new InvalidArgumentException(sprintf('Invalid #[Target] name "%s" on parameter "$%s" of "%s()": the first character must be a letter.', $name$parameter->name, $function));
        }

        return $parsedName;
    }
}
/** * Handles unresolved arguments for getArgument(). * * Subclasses that override this method may return a default value * instead of throwing an exception. * * @throws \RuntimeException * Thrown when there is a missing parameter. */
  protected function handleUnresolvedArgument(\ReflectionParameter $parameter) {
    $class = $parameter->getDeclaringClass();
    $function = $parameter->getDeclaringFunction();
    if ($class && !$function->isClosure()) {
      $function_name = $class->getName() . '::' . $function->getName();
    }
    else {
      $function_name = $function->getName();
    }
    throw new \RuntimeException(sprintf('Callable "%s" requires a value for the "$%s" argument.', $function_name$parameter->getName()));
  }

}

class InvalidParameterTypeException extends InvalidArgumentException
{
    public function __construct(string $serviceId, string $type, \ReflectionParameter $parameter)
    {
        $acceptedType = $parameter->getType();
        $acceptedType = $acceptedType instanceof \ReflectionNamedType ? $acceptedType->getName() : (string) $acceptedType;
        $this->code = $type;

        $function = $parameter->getDeclaringFunction();
        $functionName = $function instanceof \ReflectionMethod
            ? sprintf('%s::%s', $function->getDeclaringClass()->getName()$function->getName())
            : $function->getName();

        parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s()" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition()$functionName$acceptedType$type));
    }
}

class InvalidParameterTypeException extends InvalidArgumentException
{
    public function __construct(string $serviceId, string $type, \ReflectionParameter $parameter)
    {
        $acceptedType = $parameter->getType();
        $acceptedType = $acceptedType instanceof \ReflectionNamedType ? $acceptedType->getName() : (string) $acceptedType;
        $this->code = $type;

        $function = $parameter->getDeclaringFunction();
        $functionName = $function instanceof \ReflectionMethod
            ? sprintf('%s::%s', $function->getDeclaringClass()->getName()$function->getName())
            : $function->getName();

        parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s()" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition()$functionName$acceptedType$type));
    }
}
Home | Imprint | This part of the site doesn't use cookies.