diff --git a/src/Concerns/OverridesCookieSettings.php b/src/Concerns/OverridesCookieSettings.php index b150cf4..3ff4e86 100644 --- a/src/Concerns/OverridesCookieSettings.php +++ b/src/Concerns/OverridesCookieSettings.php @@ -14,24 +14,9 @@ trait OverridesCookieSettings { /** - * @var string|null + * @var array{path?:string|null,domain?:string|null,secure?:bool|null,same_site?:string|null} */ - protected static ?string $path = null; - - /** - * @var string|null - */ - protected static ?string $domain = null; - - /** - * @var bool|null - */ - protected static ?bool $secure = null; - - /** - * @var string|null - */ - protected static ?string $sameSite = null; + protected static array $settings = []; /** * Set the cookie domain @@ -42,7 +27,7 @@ trait OverridesCookieSettings */ public static function setDomain(?string $domain): void { - self::$domain = $domain; + self::$settings['domain'] = $domain; } /** @@ -54,7 +39,7 @@ public static function setDomain(?string $domain): void */ public static function setPath(?string $path): void { - self::$path = $path; + self::$settings['path'] = '/' . ltrim($path, '/'); } // @codeCoverageIgnoreStart @@ -68,7 +53,7 @@ public static function setPath(?string $path): void */ public static function setSameSite(?string $sameSite): void { - self::$sameSite = $sameSite; + self::$settings['same_site'] = $sameSite; } /** @@ -80,7 +65,7 @@ public static function setSameSite(?string $sameSite): void */ public static function setSecure(?bool $secure): void { - self::$secure = $secure; + self::$settings['secure'] = $secure; } // @codeCoverageIgnoreEnd } diff --git a/src/Overrides/CookieOverride.php b/src/Overrides/CookieOverride.php index 8aa1c22..798da88 100644 --- a/src/Overrides/CookieOverride.php +++ b/src/Overrides/CookieOverride.php @@ -47,10 +47,10 @@ public static function service(): string public function setup(Tenancy $tenancy, Tenant $tenant): void { // Collect the values - $path = self::$path ?? config('session.path') ?? '/'; - $domain = self::$domain ?? config('session.domain'); - $secure = self::$secure ?? config('session.secure', false); - $sameSite = self::$sameSite ?? config('session.same_site'); + $path = self::$settings['path'] ?? config('session.path') ?? '/'; + $domain = self::$settings['domain'] ?? config('session.domain'); + $secure = self::$settings['secure'] ?? config('session.secure', false); + $sameSite = self::$settings['same_site'] ?? config('session.same_site'); /** * This is here to make PHPStan quiet down diff --git a/src/Overrides/SessionOverride.php b/src/Overrides/SessionOverride.php index ef9df10..8c250ca 100644 --- a/src/Overrides/SessionOverride.php +++ b/src/Overrides/SessionOverride.php @@ -99,29 +99,15 @@ public function boot(Application $app, Sprout $sprout): void */ public function setup(Tenancy $tenancy, Tenant $tenant): void { - // Collect the values - $path = self::$path ?? config('session.path') ?? '/'; - $domain = self::$domain ?? config('session.domain'); - $secure = self::$secure ?? config('session.secure', false); - $sameSite = self::$sameSite ?? config('session.same_site'); - - /** - * This is here to make PHPStan quiet down - * - * @var string $path - * @var string|null $domain - * @var bool|null $secure - * @var string|null $sameSite - */ + $settings = self::$settings; /** @var \Illuminate\Contracts\Config\Repository $config */ $config = config(); - // Set the config values - $config->set('session.path', $path); - $config->set('session.domain', $domain); - $config->set('session.secure', $secure); - $config->set('session.same_site', $sameSite); + foreach ($settings as $setting => $value) { + $config->set('session.' . $setting, $value); + } + $config->set('session.cookie', $this->getCookieName($tenancy, $tenant)); // Reset all the drivers