server_url = $url; $this->api_key = $key; $this->local_url = $local_url; } /** * PHP magic function for handling the calling of services * * @param string $name Name of function called * @param array $args Arguments passed */ public function __call($name, $args){ $http = new HTTP_Request($this->server_url, array('method' => HTTP_REQUEST_METHOD_POST)); $postdata = array( 'key' => $this->api_key, 'url' => $this->local_url, 'service' => $name, 'args' => serialize($args) ); // error_log(base64_encode(serialize($postdata))); $http->addPostData('c', base64_encode(serialize($postdata))); $http->sendRequest(); $code = $http->getResponseCode(); if ($code != '200') { switch($code){ case '404': throw new fontservException('The FontServ.com API could not be contacted, Internet access is required when using services from FontServ.com.'); break; case '500': throw new fontservException('Unknown Server Error, Please try again in a few moments'); break; default: throw new fontservException('Server Response Code: '.$code.'. Please contact support.'); break; } } $response = unserialize(base64_decode($http->getResponseBody())); if ($response instanceof fontservException) { throw $response; } return $response; } } /** * An RPC Exception class, used for handling, surprisingly, * errors. */ class fontservException extends Exception{} ?>