aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz/Request.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Minz/Request.php')
-rw-r--r--lib/Minz/Request.php41
1 files changed, 20 insertions, 21 deletions
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 6d099a555..301bd5623 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -19,7 +19,7 @@ class Minz_Request {
private static string $default_controller_name = 'index';
private static string $default_action_name = 'index';
- /** @var array{'c'?:string,'a'?:string,'params'?:array<string,mixed>} */
+ /** @var array{c?:string,a?:string,params?:array<string,mixed>} */
private static array $originalRequest = [];
/**
@@ -35,6 +35,7 @@ class Minz_Request {
public static function params(): array {
return self::$params;
}
+
/**
* Read the URL parameter
* @param string $key Key name
@@ -46,10 +47,8 @@ class Minz_Request {
public static function param(string $key, $default = false, bool $specialchars = false) {
if (isset(self::$params[$key])) {
$p = self::$params[$key];
- if (is_object($p) || $specialchars) {
- return $p;
- } elseif (is_string($p) || is_array($p)) {
- return Minz_Helper::htmlspecialchars_utf8($p);
+ if (is_string($p) || is_array($p)) {
+ return $specialchars ? $p : Minz_Helper::htmlspecialchars_utf8($p);
} else {
return $p;
}
@@ -58,12 +57,15 @@ class Minz_Request {
}
}
- /** @return array<string|int,string|array<string,string|int>> */
+ public static function hasParam(string $key): bool {
+ return isset(self::$params[$key]);
+ }
+
+ /** @return array<string|int,string|array<string,string|int|bool>> */
public static function paramArray(string $key, bool $specialchars = false): array {
if (empty(self::$params[$key]) || !is_array(self::$params[$key])) {
return [];
}
-
return $specialchars ? Minz_Helper::htmlspecialchars_utf8(self::$params[$key]) : self::$params[$key];
}
@@ -131,7 +133,7 @@ class Minz_Request {
public static function defaultActionName(): string {
return self::$default_action_name;
}
- /** @return array{'c':string,'a':string,'params':array<string,mixed>} */
+ /** @return array{c:string,a:string,params:array<string,mixed>} */
public static function currentRequest(): array {
return [
'c' => self::$controller_name,
@@ -140,14 +142,14 @@ class Minz_Request {
];
}
- /** @return array{'c'?:string,'a'?:string,'params'?:array<string,mixed>} */
+ /** @return array{c?:string,a?:string,params?:array<string,mixed>} */
public static function originalRequest() {
return self::$originalRequest;
}
/**
* @param array<string,mixed>|null $extraParams
- * @return array{'c':string,'a':string,'params':array<string,mixed>}
+ * @return array{c:string,a:string,params:array<string,mixed>}
*/
public static function modifiedCurrentRequest(?array $extraParams = null): array {
unset(self::$params['ajax']);
@@ -169,14 +171,13 @@ class Minz_Request {
self::$action_name = ctype_alnum($action_name) ? $action_name : '';
}
- /** @param array<string,string> $params */
+ /** @param array<string,mixed> $params */
public static function _params(array $params): void {
self::$params = $params;
}
- /** @param array|mixed $value */
- public static function _param(string $key, $value = false): void {
- if ($value === false) {
+ public static function _param(string $key, ?string $value = null): void {
+ if ($value === null) {
unset(self::$params[$key]);
} else {
self::$params[$key] = $value;
@@ -382,7 +383,7 @@ class Minz_Request {
/**
* Restart a request
- * @param array{'c'?:string,'a'?:string,'params'?:array<string,mixed>} $url an array presentation of the URL to route to
+ * @param array{c?:string,a?:string,params?:array<string,mixed>} $url an array presentation of the URL to route to
* @param bool $redirect If true, uses an HTTP redirection, and if false (default), performs an internal dispatcher redirection.
* @throws Minz_ConfigurationException
*/
@@ -400,10 +401,8 @@ class Minz_Request {
} else {
self::_controllerName($url['c']);
self::_actionName($url['a']);
- self::_params(array_merge(
- self::$params,
- $url['params']
- ));
+ $merge = array_merge(self::$params, $url['params']);
+ self::_params($merge);
Minz_Dispatcher::reset();
}
}
@@ -411,7 +410,7 @@ class Minz_Request {
/**
* Wrappers good notifications + redirection
* @param string $msg notification content
- * @param array{'c'?:string,'a'?:string,'params'?:array<string,mixed>} $url url array to where we should be forwarded
+ * @param array{c?:string,a?:string,params?:array<string,mixed>} $url url array to where we should be forwarded
*/
public static function good(string $msg, array $url = []): void {
Minz_Request::setGoodNotification($msg);
@@ -421,7 +420,7 @@ class Minz_Request {
/**
* Wrappers bad notifications + redirection
* @param string $msg notification content
- * @param array{'c'?:string,'a'?:string,'params'?:array<string,mixed>} $url url array to where we should be forwarded
+ * @param array{c?:string,a?:string,params?:array<string,mixed>} $url url array to where we should be forwarded
*/
public static function bad(string $msg, array $url = []): void {
Minz_Request::setBadNotification($msg);