0 follower

Final Class Yiisoft\RequestModel\Attribute\BodyResolver

InheritanceYiisoft\RequestModel\Attribute\BodyResolver
ImplementsYiisoft\RequestModel\Attribute\HandlerParameterResolverInterface

Method Details

Hide inherited methods

resolve() public method

public mixed resolve ( Yiisoft\RequestModel\Attribute\HandlerParameterAttributeInterface $attribute, \Psr\Http\Message\ServerRequestInterface $request )
$attribute Yiisoft\RequestModel\Attribute\HandlerParameterAttributeInterface
$request \Psr\Http\Message\ServerRequestInterface

                public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed
{
    if ($attribute::class !== Body::class) {
        throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Body::class, $attribute::class));
    }
    $parsedBody = $request->getParsedBody();
    if ($attribute->getName() !== null) {
        if (!is_array($parsedBody)) {
            throw new ValueNotFoundException();
        }
        return $parsedBody[$attribute->getName()] ?? throw new ValueNotFoundException();
    }
    return $parsedBody;
}