Pimcore\Tool\RestClient::doRequest PHP Метод

doRequest() публичный Метод

public doRequest ( $uri, string $method = "GET", null $body = null ) : mixed | null | string
$uri
$method string
$body null
Результат mixed | null | string
    public function doRequest($uri, $method = "GET", $body = null)
    {
        $client = $this->client;
        $client->setMethod($method);
        if ($this->loggingEnabled) {
            print "    " . $method . " " . $uri . "\n";
        }
        $client->setUri($uri);
        if ($body != null && ($method == "PUT" || $method == "POST")) {
            $client->setRawData($body);
            //                print("    body: " . $body . "\n");
        }
        $result = $client->request();
        $body = $result->getBody();
        $statusCode = $result->getStatus();
        if ($statusCode != 200) {
            throw new Exception("Status code " . $statusCode . " " . $uri);
        }
        if ($result->getHeader('content-type') != 'application/json') {
            throw new Exception("No JSON response header " . $statusCode . " " . $uri);
        }
        $bodyObj = json_decode($body);
        if ($bodyObj === null) {
            throw new \Exception("No valid JSON data: '" . $body . "'");
        }
        return $bodyObj;
    }