Final Class Yiisoft\Input\Http\Attribute\Data\FromBodyResolver
| Inheritance | Yiisoft\Input\Http\Attribute\Data\FromBodyResolver |
|---|---|
| Implements | Yiisoft\Hydrator\Attribute\Data\DataAttributeResolverInterface |
Resolver for {@see FromBody} attribute.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Input\Http\Attribute\Data\FromBodyResolver | |
| prepareData() | Yiisoft\Input\Http\Attribute\Data\FromBodyResolver |
Method Details
| public mixed __construct ( \Yiisoft\RequestProvider\RequestProviderInterface $requestProvider ) | ||
| $requestProvider | \Yiisoft\RequestProvider\RequestProviderInterface |
The request provider. |
public function __construct(
private RequestProviderInterface $requestProvider,
) {
}
| public \Yiisoft\Hydrator\DataInterface prepareData ( \Yiisoft\Hydrator\Attribute\Data\DataAttributeInterface $attribute, \Yiisoft\Hydrator\DataInterface $data ) | ||
| $attribute | \Yiisoft\Hydrator\Attribute\Data\DataAttributeInterface | |
| $data | \Yiisoft\Hydrator\DataInterface | |
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());
}
Signup or Login in order to comment.