Session class final
One request's session (Laravel's Illuminate\Session\Store): a map of
attributes loaded from a SessionHandler at the start of the request
and written back at its end, so a Laravel application sharing the store
reads the same session.
Both of Laravel's formats are read, PHP serialize() and JSON. A session
is written back in the format it was read in, whatever serialization
says: rewriting a row in the other format would log the user out of the
Laravel application. serialization decides for new sessions only.
Flash data (_flash.new, _flash.old), the CSRF token (_token) and
the previous URL (_previous.url) use Laravel's keys.
Constructors
- Session({required String name, required SessionHandler handler, String? id, Encrypter? encrypter, String serialization = 'php'})
-
A session read through
handler.
Properties
-
all
→ Map<
String, Object?> -
Every attribute, including the framework's
_token,_flashand_previousentries.no setter - encrypter → Encrypter?
-
With
SESSION_ENCRYPT, the encrypter of the payload: Laravel'sEncryptedStorestoresCrypt::encrypt(serialize($attributes)), a serialized string inside theCryptpayload.final -
errors
→ Map<
String, Object?> -
The validation errors a failed request flashed, by field, whichever
application flashed them.
no setter
- handler → SessionHandler
-
Reads and writes the payload.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
The session id (the cookie value).
no setter
- isStarted → bool
-
Whether start has run.
no setter
- name → String
-
The cookie name.
final
- previousUrl ↔ String?
-
The previous URL, for
back().getter/setter pair -
queuedCookies
→ Map<
String, (String?, Duration?)> -
Cookies StartSessionMiddleware adds to the response, by name: a
nullvalue forgets the cookie.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serialization → String
-
phporjson: the format of a session that has no stored payload yet (SESSION_SERIALIZATION).final - token → String?
-
The CSRF token.
no setter
Methods
-
ageFlashData(
) → void -
Laravel's
ageFlashData: forgets last request's flash data and marks this request's as old. -
decrement(
String key, [int amount = 1]) → int -
Subtracts
amountfrom the integer atkeyand returns it. -
exists(
String key) → bool -
Whether
keyis set, even to null. -
flash(
String key, [Object? value = true]) → void -
Keeps
valuefor the next request only. -
flashErrors(
Map< String, List< messages, {String bag = 'default'}) → voidString> > -
Flashes validation
messagesunderbag. A PHP session gets Laravel'sViewErrorBag:ShareErrorsFromSessionpasses on anything truthy, so an array would fail withgetBags() on arrayon a page Laravel renders. -
flush(
) → void - Removes every value.
-
forget(
String key) → void -
Removes
key. -
get<
T> (String key, [T? fallback]) → T? -
The value of
key(dotted), orfallback. -
has(
String key) → bool -
Whether
keyholds a non-null value. -
increment(
String key, [int amount = 1]) → int -
Adds
amountto the integer atkeyand returns it. -
invalidate(
) → Future< void> - Empties the session and gives it a new id (logout).
-
keep(
List< String> keys) → void -
Keeps the given flashed
keysfor one more request. -
migrate(
{bool destroy = false}) → Future< void> -
A new id without a new token (Laravel's
migrate). -
missing(
String key) → bool -
Whether
keyis not set. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
now(
String key, Object? value) → void -
Keeps
valuefor this request only. -
old<
T> (String key, [T? fallback]) → T? -
old('name'): the input of the failed request. -
pull<
T> (String key, [T? fallback]) → T? -
Gets
keyand forgets it. -
push(
String key, Object? value) → void -
Appends
valueto the list underkey. -
put(
String key, Object? value) → void -
Sets
keytovalue. -
reflash(
) → void - Keeps every flashed value for one more request.
-
regenerate(
{bool destroy = false}) → Future< void> -
Gives the session a new id, keeping its data (Laravel's
regenerate); withdestroythe old record is deleted. -
regenerateToken(
) → void - Gives the session a new CSRF token.
-
remember<
T> (String key, T value()) → T -
Puts
keyonly when it is missing. -
save(
{Request? request}) → Future< void> - Ages the flash data and writes the attributes back.
-
start(
) → Future< void> - Loads the attributes from the handler and makes sure a CSRF token exists.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
Static Methods
-
generateId(
) → String - A new random session id.
-
isValidId(
String id) → bool -
40 alphanumeric characters (Laravel's
isValidId).