/** * Execute an HTTP query based on a qurey/response object * * After executing the underlying PHP query function, the server response * is parsed by the response object. * * This method should not be invoked directly, but instead through * {@link makeQuery()} * * @param Cpanel_Query_Object $rObj Query object responsible for parsing * server response * * @see makeQuery() * * @return Cpanel_Query_Object * @throws Exception If invalid $rObj * @throws Exception If $rObj specifies a PHP query function that does not * have a corresponding proxy method in Cpanel_Query_Http_Abstract */ public function exec($rObj) { if (!$rObj instanceof Cpanel_Query_Object) { throw new Exception('Invalid QueryObject'); } $client = $rObj->query->client; $func = "{$client}Query"; if (empty($client) || !method_exists($this, $func)) { throw new Exception("Query client {$client} is not defined"); } return $rObj->parse($this->{$func}($rObj)); }
* the PHP SimpleXML functions to decode the string */ $simplxml = simplexml_load_string($raw); echo "WHM Version: {$simplxml->version}\n"; /** * The following example illustrates a direct URL query against * $server:2087/json-api/listaccts?serchtype=domain&search=dave.com * and passing a custom header 'CustomHeader=CustomSendValue' */ $url = '/json-api/listaccts'; $formdata = array('searchtype' => 'domain', 'search' => 'dave.com'); $response = $cp->api_request('WHM', $url, 'GET', $formdata, array('CustomHeader' => 'CustomSendValue')); $raw = $response->getRawResponse(); /** * Again, decode appropriately. * * Here, we'll use the cPanel PHP library's JSON parser class */ $newResponse = new Cpanel_Query_Object(); $newResponse->setResponseFormatType('JSON'); $newResponse->parse($raw); echo "Dave's Domain Detail:\n"; foreach ($newResponse->acct as $acct) { foreach ($acct as $key => $value) { echo "\t{$key}: {$value}\n"; } } } catch (Exception $e) { echo $e->getMessage() . "\n" . $e->getTraceAsString() . "\n"; } echo "EOF: You've successfully ended the " . basename(__FILE__) . " script.\n";