Final Class Yiisoft\Input\Http\Attribute\Parameter\BodyResolver
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Resolver for {@see Body} attribute.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getParameterValue() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $requestProvider | \ |
The request provider. |
public function __construct(
private RequestProviderInterface $requestProvider,
) {}
| public \ | ||
| $attribute | \ |
|
| $context | \ |
|
public function getParameterValue(
ParameterAttributeInterface $attribute,
ParameterAttributeResolveContext $context,
): Result {
if (!$attribute instanceof Body) {
throw new UnexpectedAttributeException(Body::class, $attribute);
}
$parsedBody = $this->requestProvider->get()->getParsedBody();
$name = $attribute->getName() ?? $context->getParameter()->getName();
if (!is_array($parsedBody)) {
return Result::fail();
}
if (!ArrayHelper::pathExists($parsedBody, $name)) {
return Result::fail();
}
return Result::success(ArrayHelper::getValueByPath($parsedBody, $name));
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.