Final Class Yiisoft\Yii\DataView\Url\UrlParametersFactory
| Inheritance | Yiisoft\Yii\DataView\Url\UrlParametersFactory |
|---|
Factory for creating URL parameters for data view components.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| create() | Create URL parameters based on the current data view state and configuration. | Yiisoft\Yii\DataView\Url\UrlParametersFactory |
Method Details
Create URL parameters based on the current data view state and configuration.
| public static create( \Yiisoft\Data\Paginator\PageToken|null $pageToken, integer|string|null $pageSize, string|null $sort, Yiisoft\Yii\DataView\Url\UrlConfig $context ): array | ||
| $pageToken | \Yiisoft\Data\Paginator\PageToken|null |
Current page token for pagination. Contains both the token value and direction (next/previous). |
| $pageSize | integer|string|null |
Number of items per page. Can be |
| $sort | string|null |
Current sort expression (e.g., 'name,-created_at'). Null means no sorting. |
| $context | Yiisoft\Yii\DataView\Url\UrlConfig |
URL configuration that defines parameter names and types. Controls how parameters are included in the URL. |
| return | array |
Two-element array containing:
|
|---|---|---|
public static function create(
?PageToken $pageToken,
int|string|null $pageSize,
?string $sort,
UrlConfig $context,
): array {
$arguments = $context->getArguments();
$queryParameters = $context->getQueryParameters();
switch ($context->getPageParameterType()) {
case UrlParameterType::Path:
/**
* @psalm-suppress PossiblyNullPropertyFetch https://github.com/vimeo/psalm/issues/10591
*/
$arguments[$context->getPageParameterName()] = $pageToken?->isPrevious === false
? $pageToken->value
: null;
break;
case UrlParameterType::Query:
/**
* @psalm-suppress PossiblyNullPropertyFetch https://github.com/vimeo/psalm/issues/10591
*/
$queryParameters[$context->getPageParameterName()] = $pageToken?->isPrevious === false
? $pageToken->value
: null;
break;
}
switch ($context->getPreviousPageParameterType()) {
case UrlParameterType::Path:
/**
* @psalm-suppress PossiblyNullPropertyFetch https://github.com/vimeo/psalm/issues/10591
*/
$arguments[$context->getPreviousPageParameterName()] = $pageToken?->isPrevious === true
? $pageToken->value
: null;
break;
case UrlParameterType::Query:
/**
* @psalm-suppress PossiblyNullPropertyFetch https://github.com/vimeo/psalm/issues/10591
*/
$queryParameters[$context->getPreviousPageParameterName()] = $pageToken?->isPrevious === true
? $pageToken->value
: null;
break;
}
switch ($context->getPageSizeParameterType()) {
case UrlParameterType::Path:
$arguments[$context->getPageSizeParameterName()] = $pageSize;
break;
case UrlParameterType::Query:
$queryParameters[$context->getPageSizeParameterName()] = $pageSize;
break;
}
switch ($context->getSortParameterType()) {
case UrlParameterType::Path:
$arguments[$context->getSortParameterName()] = $sort;
break;
case UrlParameterType::Query:
$queryParameters[$context->getSortParameterName()] = $sort;
break;
}
return [$arguments, $queryParameters];
}
Signup or Login in order to comment.