-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discovery: STUB: Add ExpireTimestampConverter.
- Loading branch information
1 parent
1b49e5d
commit ceea53e
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\collabora_online\Time; | ||
|
||
use Drupal\Component\Datetime\TimeInterface; | ||
use Drupal\Core\Cache\Cache; | ||
|
||
/** | ||
* Service to convert between expire timestamp and cache max-age value. | ||
*/ | ||
class ExpireTimestampConverter { | ||
|
||
public function __construct( | ||
protected readonly TimeInterface $time, | ||
) {} | ||
|
||
public function getExpireTimestamp(int $max_age): int { | ||
if ($max_age === Cache::PERMANENT) { | ||
return Cache::PERMANENT; | ||
} | ||
return $max_age + $this->time->getRequestTime(); | ||
} | ||
|
||
public function getMaxAge(int $expire): int { | ||
if ($expire === Cache::PERMANENT) { | ||
return Cache::PERMANENT; | ||
} | ||
return $expire - $this->time->getRequestTime(); | ||
} | ||
|
||
} |