| Total Complexity | 5 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Coverage | 25% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class DarkModeController extends Controller |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * The key to use for save dark mode status on the session. |
||
| 9 | * |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | protected $sessionKey = 'adminlte_dark_mode'; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Toggle the dark mode status. |
||
| 16 | * |
||
| 17 | * @return void |
||
| 18 | */ |
||
| 19 | public function toggle() |
||
| 20 | { |
||
| 21 | // Store the new darkmode status on the session. This way, we can keep |
||
| 22 | // the dark mode preference over multiple requests. |
||
| 23 | |||
| 24 | session([$this->sessionKey => ! $this->isEnabled()]); |
||
| 25 | |||
| 26 | // TODO: We can trigger/dispatch an event so the end user may have a |
||
| 27 | // way to catch the new darkmode status and update the preference on a |
||
| 28 | // database, for example. |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Check if the dark mode is enabled or not. |
||
| 33 | * |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | 12 | public function isEnabled() |
|
| 37 | { |
||
| 38 | // First, check if dark mode status was previously saved on the session. |
||
| 39 | |||
| 40 | 12 | if (! is_null(session($this->sessionKey, null))) { |
|
| 41 | return session($this->sessionKey); |
||
| 42 | } |
||
| 43 | |||
| 44 | // Otherwise, fallback to the default package configuration value. |
||
| 45 | |||
| 46 | 12 | return (bool) config('adminlte.layout_dark_mode', false); |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Enables the dark mode. |
||
| 51 | * |
||
| 52 | * @return void |
||
| 53 | */ |
||
| 54 | public function enable() |
||
| 55 | { |
||
| 56 | session([$this->sessionKey => true]); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Disables the dark mode. |
||
| 61 | * |
||
| 62 | * @return void |
||
| 63 | */ |
||
| 64 | public function disable() |
||
| 67 | } |
||
| 68 | } |
||
| 69 |