0

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;
        },
ChamingaD
  • 2,908
  • 8
  • 35
  • 58
  • would be better to move this to a factory – Vytautas Nov 21 '13 at 14:22
  • speed, you can cashe config and will be created only when you need them read more here http://stackoverflow.com/questions/19479175/factory-classes-vs-closures-in-zend-framework-2 or google clousure vs factory – Vytautas Nov 22 '13 at 07:54

0 Answers0