self::MAX_LIFETIME_DAYS) { throw new InvalidConfiguration(esc_html(sprintf(/* translators: %d: maximum number of days */ __('Consent lifetime must be between 1 and %d days.', 'mortar-consent'), self::MAX_LIFETIME_DAYS))); } } public function lifetimeSeconds(): int { return $this->lifetimeDays * 86400; } public function isCurrent(ConsentState $state, int $now): bool { return $state->policyVersion === $this->version && $state->timestamp <= $now + 300 // tolerate small clock skew from the visitor's device && $now - $state->timestamp <= $this->lifetimeSeconds(); } public function allows(?ConsentState $state, string $categoryId, int $now): bool { if (! $this->categories->has($categoryId)) { return false; } if (! $this->categories->isOptional($categoryId)) { return true; } return $state !== null && $this->isCurrent($state, $now) && $state->grants($categoryId); } }