ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ProofKeyRefresh.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WOPI\Discovery;
22
33final class ProofKeyRefresh
34{
35 public const MIN_INTERVAL = 5 * 60;
36 private const LAST_REFRESH = 'wopi_proof_refreshed_at';
37
41 private \Closure $clock;
42
47 public function __construct(
48 private ProofKeyRepository $repository,
49 private \ilSetting $settings,
50 private \Closure $fetch,
51 ?\Closure $clock = null
52 ) {
53 $this->clock = $clock ?? static fn(): int => time();
54 }
55
59 public function __invoke(): ?ProofKeys
60 {
61 $now = ($this->clock)();
62 if ($now - (int) $this->settings->get(self::LAST_REFRESH, '0') < self::MIN_INTERVAL) {
63 return null;
64 }
65 $this->settings->set(self::LAST_REFRESH, (string) $now);
66
67 try {
68 $keys = ($this->fetch)();
69 } catch (\Throwable) {
70 return null;
71 }
72 if ($keys === null) {
73 return null;
74 }
75 $this->repository->store($keys);
76
77 return $keys;
78 }
79}
$settings
Definition: index.php:44
Fetches the proof keys from the discovery again when a request could not be verified with the stored ...
__construct(private ProofKeyRepository $repository, private \ilSetting $settings, private \Closure $fetch, ?\Closure $clock=null)
The current and the previous proof key of a WOPI client.
Definition: ProofKeys.php:30
ILIAS Setting Class.