3 #pre-php 5.4 compatible version?
4 function flatten($hash) {
5 if ( !is_array($hash) ) return $hash;
8 array_walk($hash, function($value, $key, &$to) {
9 array_push($to, $key, $value);
12 if ( PHP_VERSION_ID >= 50400 ) {
15 foreach ($hash as $key => $value) {
26 #function flatten($hash) {
27 # if ( !is_array($hash) ) return $hash;
31 # foreach ($hash as $key => $value) {
39 class FreesideSelfService {
41 //Change this to match the location of your selfservice xmlrpc.cgi or daemon
42 #var $URL = 'https://localhost/selfservice/xmlrpc.cgi';
43 #var $URL = 'http://localhost/selfservice/xmlrpc.cgi';
44 var $URL = 'http://localhost:8080/';
46 function FreesideSelfService() {
50 public function __call($name, $arguments) {
52 error_log("[FreesideSelfService] $name called, sending to ". $this->URL);
54 $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", flatten($arguments[0]));
55 $context = stream_context_create( array( 'http' => array(
57 'header' => "Content-Type: text/xml",
60 $file = file_get_contents($this->URL, false, $context);
61 $response = xmlrpc_decode($file);
62 // uncomment to trace everything
63 //error_log(print_r($response, true));
64 if (xmlrpc_is_fault($response)) {
65 trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
67 //error_log("[FreesideSelfService] $response");