PHP: Functions, Parameters, SOAP

Asked

Viewed 246 times

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 have no way of knowing how many parameters the turn function asks for.

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

1 answer

1


in his method Send(), you can treat the return of __getFunctions to get the list of arguments needed. 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.

Maybe not the best solution, but in the absence of something better is an option.

ex. ("head" and not tested because I am without PHP here and I haven’t programmed 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;
    }
  }
}
  • It’s a valid solution yes, thanks Daniel

Browser other questions tagged

You are not signed in. Login or sign up in order to post.