Skip to content
This repository has been archived by the owner on Jan 13, 2020. It is now read-only.

Latest commit

 

History

History
57 lines (45 loc) · 1.66 KB

README.md

File metadata and controls

57 lines (45 loc) · 1.66 KB

SoapCalculator

Before the days of REST APIs the world used SOAP web services. Instead of JSON, we used XML to communicate. Soap clients in PHP are simple to understand and follow. You'll first need a WSDL, which acts as instructions of what you can request and expect as response.

This project utilized a public SOAP Web Service which provides 4 methods Add, Subtract, Multiply, Divide.

The code

The project is follows the clear-architecture. On the abstract port layer you'll find the bulk of the code.

$soapClient = new \SoapClient($this->wsdl);
  $input = [
    'intA' => $inputs[0],
    'intB' => $inputs[1]
  ];

The request gets sent to the Soap web service and a specific method is utilized to read the response.

switch ($operator) {
    case '+':
        $response = $soapClient->Add($input);
        return $response->AddResult;
        break;
    case '-':
        $response = $soapClient->Subtract($input);
        return $response->SubtractResult;
        break;
    case '*':
        $response = $soapClient->Multiply($input);
        return $response->MultiplyResult;
        break;
    case '/':
        $response = $soapClient->Divide($input);
        return $response->DivideResult;
        break;
}

About me

I'm American living and working in Germany.

Todos

  • Fork it
  • Code it!
  • Do it on your own!

License

MIT