fix Drupal argument passing, #9380
[freeside.git] / fs_selfservice / drupal / freeside.class.php
1 <?php
2
3 function flatten($hash) {
4   if ( !is_array($hash) ) return $hash;
5   $flat = array();
6   array_walk($hash, function($value, $key, &$to) { 
7     array_push($to, $key, $value);
8   }, &$flat);
9   return($flat);
10 }
11
12 class FreesideSelfService  {
13
14   public $URL = '';
15     function FreesideSelfService() {
16       $this->URL = 'http://' . variable_get('freeside_hostname','') . ':8080';
17       $this;
18     }
19
20   public function __call($name, $arguments) {
21
22     error_log("[FreesideSelfService] $name called, sending to ". $this->URL);
23     $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", 
24       flatten($arguments[0])
25     );
26     $context = stream_context_create( array( 'http' => array(
27       'method' => "POST",
28       'header' => "Content-Type: text/xml",
29       'content' => $request
30     )));
31     $file = file_get_contents($this->URL, false, $context);
32     $response = xmlrpc_decode($file);
33     if (xmlrpc_is_fault($response)) {
34       trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
35     } else {
36       //error_log("[FreesideSelfService] $response");
37       return $response;
38     }
39   }
40
41 }
42
43 ?>