Kelunik\Acme\AcmeClient::getResourceUri PHP Method

getResourceUri() private method

Returns the URI to a resource by querying the directory. Can also handle URIs and returns them directly.
private getResourceUri ( string $resource ) : Amp\Promise
$resource string URI or directory entry
return Amp\Promise resolves to the resource URI
    private function getResourceUri($resource)
    {
        if (!is_string($resource)) {
            throw new InvalidArgumentException(sprintf("\$resource must be of type string, %s given.", gettype($resource)));
        }
        // ACME MUST be served over HTTPS, but we use HTTP for testing …
        if (substr($resource, 0, 7) === "http://" || substr($resource, 0, 8) === "https://") {
            return new Success($resource);
        }
        if (!$this->directory) {
            return \Amp\pipe(\Amp\resolve($this->fetchDirectory()), function () use($resource) {
                return $this->getResourceUri($resource);
            });
        }
        if (isset($this->directory[$resource])) {
            return new Success($this->directory[$resource]);
        }
        return new Failure(new AcmeException("Resource not found in directory: '{$resource}'."));
    }