ImpersonationService
in package
Service for managing user impersonation sessions.
Allows admins to impersonate clients or customers, and clients to impersonate their own customers. All impersonation sessions are logged.
Tags
Table of Contents
Constants
- SESSION_KEY = 'impersonation'
Methods
- getContext() : array<string|int, mixed>|null
- Get the current impersonation context.
- isImpersonating() : bool
- Check if an impersonation session is currently active.
- startClientImpersonation() : void
- Start impersonating a client (business owner).
- startCustomerImpersonation() : void
- Start impersonating a customer.
- stop() : string
- Stop the current impersonation session.
Constants
SESSION_KEY
private
string
SESSION_KEY
= 'impersonation'
Session key for impersonation context
Methods
getContext()
Get the current impersonation context.
public
static getContext() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —Context array or null if not impersonating
isImpersonating()
Check if an impersonation session is currently active.
public
static isImpersonating() : bool
Return values
boolstartClientImpersonation()
Start impersonating a client (business owner).
public
static startClientImpersonation(array<string|int, mixed> $admin, array<string|int, mixed> $user, array<string|int, mixed> $business) : void
Only callable by an admin. Sets up the client guard session and stores impersonation context for banner display.
Parameters
- $admin : array<string|int, mixed>
-
Admin user record
- $user : array<string|int, mixed>
-
Client user record to impersonate
- $business : array<string|int, mixed>
-
Business record for the client
startCustomerImpersonation()
Start impersonating a customer.
public
static startCustomerImpersonation(array<string|int, mixed> $customer, string $slug, string $callerGuard, int $callerId, string $callerName, string $returnUrl) : void
Callable by admin or client. Sets up the customer guard session and stores impersonation context.
Parameters
- $customer : array<string|int, mixed>
-
Customer record to impersonate
- $slug : string
-
Business slug for storefront redirect
- $callerGuard : string
-
Guard of the caller (admin or client)
- $callerId : int
-
ID of the caller
- $callerName : string
-
Name of the caller
- $returnUrl : string
-
URL to return to after stopping
stop()
Stop the current impersonation session.
public
static stop() : string
Clears the target guard session, logs the end time, and returns the URL to redirect back to.
Return values
string —Redirect URL