I have third party soap service which needs to be called from Zend 2 application. They have given the client source code. I put it's creation and login code in global.php file as below. So client will be automatically created and available as a service. Login will occur if session is not found.
Is it a good way ?
This service is used only on some pages/modules of the site. As i feel, in this way client will login to the soap server even it has no use.
'SfClient' => function($sm) {
$config = $sm->get('config');
$sf_wsdl = $config['salesforce']['wsdl'];
$sf_username = $config['salesforce']['username'];
$sf_password = $config['salesforce']['password'];
$sf_token = $config['salesforce']['token'];
try {
//Call Soap Client Builder
$builder = new \Salesforce\SoapClient\ClientBuilder(
$sf_wsdl, $sf_username, $sf_password, $sf_token
);
$client = $builder->build();
} catch (\Exception $ex) {
\Zend\Debug\Debug::dump($ex);
}
return $client;
},