Remove last traces of date functions in favor of DateTimeImmutable

This commit is contained in:
Alex Cabal 2024-06-13 13:11:42 -05:00
parent c6d2d77537
commit 97821d0dc3
4 changed files with 7 additions and 13 deletions

View file

@ -188,7 +188,7 @@ class HttpInput{
try{ try{
return intval($var); return intval($var);
} }
catch(Exception){ catch(\Exception){
return null; return null;
} }
} }
@ -205,7 +205,7 @@ class HttpInput{
try{ try{
return floatval($var); return floatval($var);
} }
catch(Exception){ catch(\Exception){
return null; return null;
} }
} }
@ -215,8 +215,7 @@ class HttpInput{
try{ try{
return new DateTimeImmutable($var); return new DateTimeImmutable($var);
} }
catch(Exception){ catch(\Exception){
vdd('q');
return null; return null;
} }
} }

View file

@ -2,8 +2,6 @@
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Safe\DateTimeImmutable; use Safe\DateTimeImmutable;
use function Safe\strtotime;
/** /**
* @property User $User * @property User $User
* @property string $Url * @property string $Url
@ -100,7 +98,7 @@ class Session{
} }
public static function SetSessionCookie(string $sessionId): void{ public static function SetSessionCookie(string $sessionId): void{
setcookie('sessionid', $sessionId, ['expires' => strtotime('+1 week'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks setcookie('sessionid', $sessionId, ['expires' => (new DateTimeImmutable('+1 week'))->format('@'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks
} }
/** /**

View file

@ -1,6 +1,5 @@
<? <?
use function Safe\apcu_fetch; use function Safe\apcu_fetch;
use function Safe\strtotime;
// If the user is not logged in, or has less than some amount of downloads, show a thank-you page // If the user is not logged in, or has less than some amount of downloads, show a thank-you page
@ -61,7 +60,7 @@ try{
// Increment local download count, expires in 2 weeks // Increment local download count, expires in 2 weeks
$downloadCount++; $downloadCount++;
setcookie('download-count', (string)$downloadCount, ['expires' => strtotime('+2 week'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); setcookie('download-count', (string)$downloadCount, ['expires' => (new DateTimeImmutable('+2 week'))->format('@'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']);
} }
catch(Exceptions\InvalidFileException | Exceptions\EbookNotFoundException){ catch(Exceptions\InvalidFileException | Exceptions\EbookNotFoundException){
Template::Emit404(); Template::Emit404();

View file

@ -1,11 +1,9 @@
<? <?
use function Safe\strtotime;
$hideDonationAlert = HttpInput::Bool(POST, 'hide-donation-alert'); $hideDonationAlert = HttpInput::Bool(POST, 'hide-donation-alert');
$colorScheme = HttpInput::Str(POST, 'color-scheme'); $colorScheme = HttpInput::Str(POST, 'color-scheme');
if($hideDonationAlert !== null){ if($hideDonationAlert !== null){
setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', ['expires' => strtotime('+1 month'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', ['expires' => (new DateTimeImmutable('+1 month'))->format('@'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
} }
if($colorScheme !== null){ if($colorScheme !== null){
@ -18,7 +16,7 @@ if($colorScheme !== null){
setcookie('color-scheme', '', ['expires' => 0, 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); setcookie('color-scheme', '', ['expires' => 0, 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
} }
else{ else{
setcookie('color-scheme', $colorScheme, ['expires' => strtotime('+1 year'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); setcookie('color-scheme', $colorScheme, ['expires' => (new DateTimeImmutable('+1 year'))->format('@'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
} }
} }