Final Class Yiisoft\Input\Http\Attribute\Data\FromBodyResolver
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Resolver for {@see FromBody} attribute.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| prepareData() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $requestProvider | \ |
The request provider. |
public function __construct(
private RequestProviderInterface $requestProvider,
) {}
| public \ | ||
| $attribute | \ |
|
| $data | \ |
|
public function prepareData(DataAttributeInterface $attribute, DataInterface $data): DataInterface
{
if (!$attribute instanceof FromBody) {
throw new UnexpectedAttributeException(FromBody::class, $attribute);
}
$array = [];
$parsedBody = $this->requestProvider->get()->getParsedBody();
if (is_array($parsedBody)) {
$name = $attribute->getName();
if ($name === null) {
$array = $parsedBody;
} else {
$value = ArrayHelper::getValueByPath($parsedBody, $name);
if (is_array($value)) {
$array = $value;
}
}
}
return new ArrayData($array, $attribute->getMap(), $attribute->isStrict());
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.