Skip to content

Commit

Permalink
paramsFromRequest list
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Sep 8, 2024
1 parent ac27f58 commit 097ef2e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions libraries/src/Pagination/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,26 @@ class Pagination
protected $additionalUrlParams = [];

/**
* Filters which will be applied to the parameters added from request.
* Defaulting to CMD when the filter is not defined here.
* List of parameters that will be added from request automatically.
* When exists they will be added to the $additionalUrlParams list, while pagination initialisation.
*
* In format key => filter
*
* @var string[]
*
* @since __DEPLOY_VERSION__
*/
protected $paramsFromRequestFilters = [
protected $paramsFromRequest = [
'format' => 'CMD',
'option' => 'CMD',
'controller' => 'CMD',
'view' => 'CMD',
'layout' => 'STRING',
'task' => 'CMD',
'template' => 'CMD',
'templateStyle' => 'INT',
'tmpl' => 'CMD',
'tpl' => 'CMD',
'id' => 'STRING',
'Itemid' => 'INT',
];
Expand Down Expand Up @@ -206,7 +216,7 @@ public function __construct($total, $limitstart, $limit, $prefix = '', CMSApplic
*/
protected function setUrlParamsFromRequest()
{
// Get requested parameters from the router
// Get the requested parameters from the router
$client = $this->app->getName();
$router = Factory::getContainer()->get(ucfirst($client) . 'Router');
$filter = new InputFilter();
Expand All @@ -218,7 +228,12 @@ protected function setUrlParamsFromRequest()

// Filter them and add to the params list
foreach ($router->getVars() as $key => $value) {
$filterMethod = $this->paramsFromRequestFilters[$key] ?? 'CMD';
// Check if the parameter is allowed
if (empty($this->paramsFromRequest[$key])) {
continue;
}

$filterMethod = $this->paramsFromRequest[$key];

$this->setAdditionalUrlParam($key, $filter->clean($value, $filterMethod));
}
Expand Down

0 comments on commit 097ef2e

Please sign in to comment.