-
Notifications
You must be signed in to change notification settings - Fork 6
Add SESSION hash support to Request class #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
69edcc8
2fcef08
ae74064
eec0b4d
e3cb224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,12 +64,13 @@ public static function getMethod() | |||||||||||||||||||||||||||||||||||||
| * - cookie $_COOKIE | ||||||||||||||||||||||||||||||||||||||
| * - env $_ENV | ||||||||||||||||||||||||||||||||||||||
| * - server $_SERVER | ||||||||||||||||||||||||||||||||||||||
| * - session $_SESSION (returns default if no active session) | ||||||||||||||||||||||||||||||||||||||
| * - method via current $_SERVER['REQUEST_METHOD'] | ||||||||||||||||||||||||||||||||||||||
| * - default $_REQUEST | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param mixed $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Source of variable value (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Source of variable value (GET, POST, FILES, COOKIE, ENV, SERVER, SESSION, METHOD, DEFAULT/REQUEST) | ||||||||||||||||||||||||||||||||||||||
| * @param string $type Return type for the variable (INT, FLOAT, BOOLEAN, WORD, | ||||||||||||||||||||||||||||||||||||||
| * ALPHANUM, CMD, BASE64, STRING, ARRAY, PATH, NONE) For more | ||||||||||||||||||||||||||||||||||||||
| * information see FilterInput::clean(). | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -106,6 +107,13 @@ public static function getVar($name, $default = null, $hash = 'default', $type = | |||||||||||||||||||||||||||||||||||||
| case 'SERVER': | ||||||||||||||||||||||||||||||||||||||
| $input = &$_SERVER; | ||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||
| case 'SESSION': | ||||||||||||||||||||||||||||||||||||||
| if (session_status() !== PHP_SESSION_ACTIVE) { | ||||||||||||||||||||||||||||||||||||||
| $input = []; | ||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| $input = &$_SESSION; | ||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||
| $input = &$_REQUEST; | ||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -114,13 +122,11 @@ public static function getVar($name, $default = null, $hash = 'default', $type = | |||||||||||||||||||||||||||||||||||||
| if (isset($input[$name]) && null !== $input[$name]) { | ||||||||||||||||||||||||||||||||||||||
| // Get the variable from the input hash and clean it | ||||||||||||||||||||||||||||||||||||||
| $var = static::cleanVar($input[$name], $mask, $type); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } elseif (null !== $default) { | ||||||||||||||||||||||||||||||||||||||
| // Clean the default value | ||||||||||||||||||||||||||||||||||||||
| $var = static::cleanVar($default, $mask, $type); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| $var = $default; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return $var; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -135,7 +141,7 @@ public static function getVar($name, $default = null, $hash = 'default', $type = | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param int $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+144
to
145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include These wrappers still accept the same fallback hashes as 📝 Suggested docblock tweak- * `@param` string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD)
+ * `@param` string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD, DEFAULT/REQUEST)Also applies to: 162-163, 180-181, 198-199, 215-216, 233-234, 249-250, 263-264, 277-278, 291-292, 305-306, 320-321 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| * @return int Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -153,7 +159,7 @@ public static function getInt($name, $default = 0, $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param float $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return float Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -171,7 +177,7 @@ public static function getFloat($name, $default = 0.0, $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param bool $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return bool Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -189,7 +195,7 @@ public static function getBool($name, $default = false, $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -206,7 +212,7 @@ public static function getWord($name, $default = '', $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -224,7 +230,7 @@ public static function getCmd($name, $default = '', $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param int $mask Filter mask for the variable | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string Requested variable | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -240,7 +246,7 @@ public static function getString($name, $default = '', $hash = 'default', $mask | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param mixed $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return array | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -254,7 +260,7 @@ public static function getArray($name, $default = array(), $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -268,7 +274,7 @@ public static function getText($name, $default = '', $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -282,7 +288,7 @@ public static function getUrl($name, $default = '', $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string Requested variable | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -296,7 +302,7 @@ public static function getPath($name, $default = '', $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string email address or default if invalid | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -311,7 +317,7 @@ public static function getEmail($name, $default = '', $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Variable name | ||||||||||||||||||||||||||||||||||||||
| * @param string $default Default value if the variable does not exist | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string IP address or default if invalid | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -385,9 +391,11 @@ public static function hasVar($name, $hash = 'default') | |||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Set a variable in one of the request variables | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * For SESSION, the write is silently skipped if no session is active. | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param string $name Name | ||||||||||||||||||||||||||||||||||||||
| * @param string $value Value | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Hash | ||||||||||||||||||||||||||||||||||||||
| * @param string $hash Hash (GET, POST, REQUEST, COOKIE, FILES, ENV, SERVER, SESSION, METHOD) | ||||||||||||||||||||||||||||||||||||||
| * @param bool $overwrite Boolean | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @return string Previous value | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -437,6 +445,11 @@ public static function setVar($name, $value = null, $hash = 'method', $overwrite | |||||||||||||||||||||||||||||||||||||
| case 'SERVER': | ||||||||||||||||||||||||||||||||||||||
| $_SERVER[$name] = $value; | ||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||
| case 'SESSION': | ||||||||||||||||||||||||||||||||||||||
| if (session_status() === PHP_SESSION_ACTIVE) { | ||||||||||||||||||||||||||||||||||||||
| $_SESSION[$name] = $value; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+449
to
+450
|
||||||||||||||||||||||||||||||||||||||
| if (session_status() === PHP_SESSION_ACTIVE) { | |
| $_SESSION[$name] = $value; | |
| if (function_exists('session_status') && defined('PHP_SESSION_ACTIVE')) { | |
| if (session_status() === PHP_SESSION_ACTIVE) { | |
| $_SESSION[$name] = $value; | |
| } |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SESSION support was added to setVar(), but the method’s docblock doesn’t mention SESSION or the no-op behavior when no session is active. Please update the setVar() documentation to include SESSION and clarify what happens when the session isn’t active.
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern as getVar(): the SESSION branch uses session_status()/PHP_SESSION_ACTIVE, which can be undefined if the session extension is disabled. Guarding here would prevent fatals and let Request::get('session') degrade to an empty array as intended.
| case 'SESSION': | |
| if (session_status() !== PHP_SESSION_ACTIVE) { | |
| $input = []; | |
| break; | |
| } | |
| case 'SESSION': | |
| if (!function_exists('session_status') || !defined('PHP_SESSION_ACTIVE')) { | |
| $input = []; | |
| break; | |
| } | |
| if (session_status() !== PHP_SESSION_ACTIVE) { | |
| $input = []; | |
| break; | |
| } | |
| if (!isset($_SESSION)) { | |
| $input = []; | |
| break; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session_status()andPHP_SESSION_ACTIVEare provided by the session extension; ifext-sessionis disabled, these calls/constants can be undefined and will fatal when$hashisSESSION. Sincecomposer.jsondoesn’t declareext-session, consider guarding theSESSIONbranch (and treating it as “no active session”) when session functions/constants aren’t available.