-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I don't want to have the `?do` links which are then disallowed in robots.txt which then Google complains about. Remove relevant lines from `robots.txt`, this reverts commit 06c4314.
- Loading branch information
Showing
14 changed files
with
143 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Application\Theme; | ||
|
||
use MichalSpacekCz\Http\Cookies\CookieName; | ||
use MichalSpacekCz\Http\Cookies\Cookies; | ||
use ValueError; | ||
|
||
readonly class Theme | ||
{ | ||
|
||
public function __construct( | ||
private Cookies $cookies, | ||
) { | ||
} | ||
|
||
|
||
public function setDarkMode(): void | ||
{ | ||
$this->setCookie(ThemeMode::Dark); | ||
} | ||
|
||
|
||
public function setLightMode(): void | ||
{ | ||
$this->setCookie(ThemeMode::Light); | ||
} | ||
|
||
|
||
public function isDarkMode(): ?bool | ||
{ | ||
$cookie = $this->cookies->getString(CookieName::Theme) ?? ''; | ||
if ($cookie === 'bright') { | ||
// Support legacy cookie value, can be removed in August 2025 because then all legacy cookies will expire | ||
$cookie = ThemeMode::Light->value; | ||
} | ||
try { | ||
return ThemeMode::from($cookie) === ThemeMode::Dark; | ||
} catch (ValueError) { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
private function setCookie(ThemeMode $mode): void | ||
{ | ||
$this->cookies->set(CookieName::Theme, $mode->value, $this->getCookieLifetime(), sameSite: 'None'); | ||
} | ||
|
||
|
||
public function getCookieLifetime(): string | ||
{ | ||
return '365 days'; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Application\Theme; | ||
|
||
enum ThemeMode: string | ||
{ | ||
|
||
case Dark = 'dark'; | ||
case Light = 'light'; | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Form; | ||
|
||
use MichalSpacekCz\Application\Theme\Theme; | ||
use MichalSpacekCz\Application\Theme\ThemeMode; | ||
|
||
readonly class ThemeFormFactory | ||
{ | ||
|
||
public function __construct( | ||
private FormFactory $factory, | ||
private Theme $theme, | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* @param callable(): void $onSuccess | ||
*/ | ||
public function create(callable $onSuccess): UiForm | ||
{ | ||
$form = $this->factory->create(); | ||
$form->addSubmit(ThemeMode::Light->value)->onClick[] = function () use ($onSuccess): void { | ||
$this->theme->setLightMode(); | ||
$onSuccess(); | ||
}; | ||
$form->addSubmit(ThemeMode::Dark->value)->onClick[] = function () use ($onSuccess): void { | ||
$this->theme->setDarkMode(); | ||
$onSuccess(); | ||
}; | ||
return $form; | ||
} | ||
|
||
} |
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
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
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
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
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
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
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
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
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
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