PHP: Functions, Parameters, SOAP

0

I have the following code with two functions:

public function getClientTemplates(){
    $client_id = 31;

    $this->Send('client_get', compact(array('client_id')));

}
public function Send($action, $post){

    extract($post);

    try {
        $data = $this->soap->$action($post);
    } catch (SoapFault $e) {
        $this->addError('ISPConfig said: SOAP Error. '.$e->getMessage());
    }
}

I have a SOAP call that needs some parameters, but I can not know how many parameters the function of the time requests.

As it is there in the code I compact and extract the variables, but I do not know how to send them without knowing their names.

    
asked by anonymous 27.04.2014 / 01:58

1 answer

1

In your Send() method, you can treat the return of __getFunctions to get the list of required arguments. With this return you can create a hash where each argument is a key. After this a merge in this hash created with your compact .

It may not be the best solution, but lacking something better is an option.

ex. ("head" and not tested because I'm without PHP here and I have not been programming PHP for a long time):

public function Send($action, $post){

  extract($post);

  $methods = $this->soap->__getFunctions();
  foreach ($methods as $method) {
    preg_match_all('/[ \t\r\n]*[ \t\r\n]?(.+)[ \t\r\n]*\(([^\)]*)\)/', $method, $matches);
    $method_name = $matches[2];
    $method_args = $matches[3];
    if ($method_name == $action) {
      try {
        $data = $this->soap->$action(array_merge($method_args, $post));
      } catch (SoapFault $e) {
        $this->addError('ISPConfig said: SOAP Error. '.$e->getMessage());
      }
      break;
    }
  }
}
    
27.04.2014 / 19:27