I will write very simple SoapClient that will connect only one server and the server has only one method. But sometimes, some controllers can share this SoapClient for retrieving some data.
I want to avoid code repetation, so, my soap client would be like this:
$data = [
//some data here
];
$client = new SoapClient("http://IPADDRESS:8080/SOAP/service?wsdl", ["trace" => 1, "exceptions" => 0]);
$xmlRow = new SimpleXMLElement('<REQUEST></REQUEST>');
$xmlRow->addChild('station', $data['d']);
$xmlRow->addChild('first', $data['t'].' '.$data['st'].':00');
$xmlRow->addChild('last',$data['t'].' '.$data['ft'].':00');
$params = new stdClass();
$params->xml = $xmlRow->asXML();
$response = $client->getCarCountForStation($params);
$this->result = simplexml_load_string($response->return);
//soapclient ends here...
dd($this->result);
/*
foreach($this->result->INFO->TRANSACTIONS->REPORT as $report)
{
foreach($report->OBJECTLIST->OBJECT as $object)
{
echo '<pre>';
print_r($object);
echo '</pre>';
}
}
*/
Commented foreach would be shared in some controllers, so i only want to write foreach part of this class in controllers (may data change)
What do you suggest to me?
I'm thinking that creating simple SoapClass for connection and creating xml and return result. Then inject into method which will use soapclient. Like this:
public function controllerAction(Mysoap $mysoap)
{
foreach($mysoap->result->INFO->TRANSACTIONS as $transactions)
{
//blabla
}
Is this way right? Or what do you suggest me? Thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire