private function doPut($token, $payload, $user = null)
{
Assert::string($token, "Token must be a string. Got: %s");
Assert::string($payload, "Payload must be a string. Got: %s");
Assert::nullOrString($user, "User must be a string or null. Got: %s");
$path = $this->docroot . "/.well-known/acme-challenge";
$realpath = realpath($path);
if (!realpath($this->docroot)) {
throw new ChallengeStoreException("Document root doesn't exist: '{$this->docroot}'");
}
if (!$realpath && !@mkdir($path, 0755, true)) {
throw new ChallengeStoreException("Couldn't create public directory to serve the challenges: '{$path}'");
}
if ($user) {
if (!($userInfo = posix_getpwnam($user))) {
throw new ChallengeStoreException("Unknown user: '{$user}'");
}
}
if (isset($userInfo)) {
(yield \Amp\File\chown($this->docroot . "/.well-known", $userInfo["uid"], -1));
(yield \Amp\File\chown($this->docroot . "/.well-known/acme-challenge", $userInfo["uid"], -1));
}
(yield \Amp\File\put("{$path}/{$token}", $payload));
if (isset($userInfo)) {
(yield \Amp\File\chown("{$path}/{$token}", $userInfo["uid"], -1));
}
(yield \Amp\File\chmod("{$path}/{$token}", 0644));
}