Ninjanoel
Ninjanoel

Reputation: 2914

SoapClient classmap inside a php namespace - soapfault class not found

I've generated a set of php classes using easyWsdl2PHP and they are working ok, but when I place the generated class inside a namespace like such...

namespace myCompany\ourService

then initially when calling this code...

$params = array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true);     
$this->soapClient = new SoapClient($url,$params);

I get this error

Class 'myCompany\ourService\SoapClient' not found

which I fix by calling new \SoapClient($url... (notice the backslash at the start, escapes the namespace), but now basically it is complaining it cant find the 'response' object, that is my Request is placed in a 'SALE' object and passed to the soap call, the error is like so

Uncaught SoapFault exception: [Client] Class 'SALEResponse' not found

How can I use php namespaces correctly within my code, how to get Soap in php to use the name spaces correctly? I have two very similar services I need to connect to, both with 'sale' methods, and many other commonly named elements that are not compatible, so placing them inside a php namespace appears to be a good solution, as the code is generated, I could rename each Sale to Service1_Sale and Service2_Sale, but that is far from ideal. Any help?

Upvotes: 1

Views: 1735

Answers (1)

Ninjanoel
Ninjanoel

Reputation: 2914

I've found a solution :

private static $classmap = array('SALE'=>'ourCompany\ourService\SALE'
,'SALEREQUEST_V1'=>'ourCompany\ourService\SALEREQUEST_V1'
,'AUTHORIZATION_V1'=>'ourCompany\ourService\AUTHORIZATION_V1'
,'RECEIPTREQUEST_V1'=>'ourCompany\ourService\RECEIPTREQUEST_V1'
,'SALEResponse'=>'ourCompany\ourService\SALEResponse'
);

where i've added the ourCompany\ourService\ to include the namespace i'm using.

Upvotes: 5

Related Questions