-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper methods to return valid query params
- Loading branch information
Showing
5 changed files
with
59 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) PutYourLightsOn | ||
*/ | ||
|
||
namespace putyourlightson\blitz\helpers; | ||
|
||
use Craft; | ||
|
||
class QueryStringHelper | ||
{ | ||
/** | ||
* Returns the valid query string params of the URI. | ||
*/ | ||
public static function getValidQueryStringParams(string $uri): array | ||
{ | ||
$queryString = parse_url($uri, PHP_URL_QUERY) ?: ''; | ||
parse_str($queryString, $queryParams); | ||
|
||
return static::getValidQueryParams($queryParams); | ||
} | ||
|
||
/** | ||
* Returns only valid query params. | ||
*/ | ||
public static function getValidQueryParams(array $queryParams): array | ||
{ | ||
$generalConfig = Craft::$app->getConfig()->getGeneral(); | ||
$invalidParams = [$generalConfig->pathParam, $generalConfig->tokenParam]; | ||
foreach ($invalidParams as $invalidParam) { | ||
if (isset($queryParams[$invalidParam])) { | ||
unset($queryParams[$invalidParam]); | ||
} | ||
} | ||
|
||
return $queryParams; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters