Last active
November 4, 2021 10:49
-
-
Save koyablue/1150419297fcfac1fdc7c5d5c1728fed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Packages\FrontPage\Shared\Presentation; | |
use App\Packages\FrontPage\Shared\UseCase\LocaleSessionInterface; | |
use App\Packages\FrontPage\Shared\Domain\Models\Locale; | |
use App\Packages\FrontPage\Shared\Presentation\Dto\GetLocaleSessionResponse; | |
class LocaleSession implements LocaleSessionInterface | |
{ | |
/** | |
* セッションキー | |
* | |
* @return string | |
*/ | |
public function getLocaleSessionKey(): string | |
{ | |
return 'locale'; | |
} | |
/** | |
* locale変更用セッション保存 | |
* | |
* @param Locale $locale | |
* @return void | |
*/ | |
public function setLocaleSession(Locale $locale) | |
{ | |
$sessionKey = $this->getLocaleSessionKey(); | |
session([$sessionKey => $locale->getLocale()]); | |
} | |
/** | |
* 現在のlocaleをセッションから取得 | |
* なければデフォルトlocale | |
* | |
* @return GetLocaleSessionResponse | |
*/ | |
public function getLocaleSession(): GetLocaleSessionResponse | |
{ | |
$sessionKey = $this->getLocaleSessionKey(); | |
$locale = session()->has($sessionKey) | |
? session($sessionKey) | |
: config('app.locale'); | |
return new GetLocaleSessionResponse($locale); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment