Final Class Yiisoft\Input\Http\Attribute\Data\FromQueryResolver
| Inheritance | Yiisoft\Input\Http\Attribute\Data\FromQueryResolver |
|---|---|
| Implements | Yiisoft\Hydrator\Attribute\Data\DataAttributeResolverInterface |
Resolver for {@see FromQuery} attribute.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Input\Http\Attribute\Data\FromQueryResolver | |
| prepareData() | Yiisoft\Input\Http\Attribute\Data\FromQueryResolver |
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 FromQuery) {
throw new UnexpectedAttributeException(FromQuery::class, $attribute);
}
$array = [];
$params = $this->requestProvider->get()->getQueryParams();
$name = $attribute->getName();
if ($name === null) {
$array = $params;
} else {
$value = ArrayHelper::getValueByPath($params, $name);
if (is_array($value)) {
$array = $value;
}
}
return new ArrayData($array, $attribute->getMap(), $attribute->isStrict());
}
Signup or Login in order to comment.