Skip to content

Session

Viames Marino edited this page Feb 23, 2026 · 1 revision

Pair framework: Session

Pair\Models\Session is the ActiveRecord model for persisted user sessions.

It also provides static helpers for PHP session values.

Main methods

Session lifecycle

  • current(): ?Session
  • destroy(): void
  • extendTimeout()
  • isExpired(int $sessionTime): bool
  • cleanOlderThan(int $sessionTime): void

User binding

  • getUser(): ?User
  • setUser(User $user): void
  • getFormerUser(): ?User
  • setFormerUser(User $formerUser)
  • hasFormerUser(): bool

PHP $_SESSION helpers

  • get(string $key): mixed
  • set(string $key, mixed $value): void
  • has(string $key): bool
  • unset(string $key): void

Implementation examples

$session = \Pair\Models\Session::current();

if ($session && $session->isExpired(60)) {
    \Pair\Models\Session::destroy();
}

Set/get session data:

\Pair\Models\Session::set('csrf', $token);
$csrf = \Pair\Models\Session::get('csrf');

See also: User, Application, Configuration-file.

Clone this wiki locally