Skip to content

Commit c33835d

Browse files
committed
feat: add append support
1 parent 84f7d16 commit c33835d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/Http/Session.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,31 @@ public static function set($key, $value = null)
101101
$_SESSION = Anchor::deepSetDot($_SESSION, $key, $value);
102102
}
103103

104+
/**
105+
* Append to data in session
106+
*
107+
* @param mixed $key The session variable key
108+
* @param mixed $value The session variable value
109+
*
110+
* @return void
111+
*/
112+
public static function append($key, $value = null)
113+
{
114+
static::start();
115+
116+
$data = static::get($key);
117+
118+
if (!$data) {
119+
$data = $value;
120+
} elseif (\is_array($data)) {
121+
$data[] = $value;
122+
} else {
123+
$data .= $value;
124+
}
125+
126+
$_SESSION = Anchor::deepSetDot($_SESSION, $key, $data);
127+
}
128+
104129
/**
105130
* Remove a session variable
106131
*/
@@ -259,4 +284,4 @@ public static function has($key)
259284
{
260285
return static::get($key) !== null;
261286
}
262-
};
287+
}

0 commit comments

Comments
 (0)