DirectAdmin\LetsEncrypt\Lib\HTTPSocket::fetch_parsed_body PHP Method

fetch_parsed_body() public method

Return parsed body in array format.
public fetch_parsed_body ( ) : array
return array result parsed
    function fetch_parsed_body()
    {
        parse_str($this->result_body, $x);
        return $x;
    }

Usage Example

Example #1
0
 /**
  * Apply certificates to DirectAdmin
  *
  * @return bool
  * @throws \Exception
  */
 public function applyCertificates()
 {
     $sock = new HTTPSocket();
     $sock->connect('127.0.0.1', 2222);
     $sock->set_login('admin');
     $sock->set_method('POST');
     $sock->query('/CMD_API_SSL', ['domain' => $this->getHostname(), 'action' => 'save', 'type' => 'paste', 'certificate' => $this->domainKeys->getPrivate() . PHP_EOL . $this->getCertificate(), 'submit' => 'Save']);
     $result = $sock->fetch_parsed_body();
     if ($result['error'] != 0) {
         throw new \Exception('Error while executing first API request: ' . $result['details']);
     }
     $sock = new HTTPSocket();
     $sock->connect('127.0.0.1', 2222);
     $sock->set_login('admin');
     $sock->set_method('POST');
     $sock->query('/CMD_API_SSL', ['domain' => $this->getHostname(), 'action' => 'save', 'type' => 'cacert', 'active' => 'yes', 'cacert' => implode("\n", $this->getCertificateAuthorityCertificates()), 'submit' => 'Save']);
     $result = $sock->fetch_parsed_body();
     if ($result['error'] != 0) {
         throw new \Exception('Error while executing second API request: ' . $result['details']);
     }
     return true;
 }