On Thu, Aug 7, 2008 at 1:29 PM, Christoph Boget <[EMAIL PROTECTED]> wrote:
> * I'm trying to better understand the 'classmap' option for the
> SoapClient class. Is it used to define the class of an instantiated
> object which will be passed as an argument to the server's function
> call? So, as a very simplistic example, it might go something like
> this:
>
> <?php
> class MyClass
> {
> public $sStockSymbol ;
> public function __construct( $sStockSymbol )
> {
> $this->sStockSymbol = $sStockSymbol;
> }
> }
>
> $oObj = new MyClass( 'ibm' );
> $oClient = new SoapClient( $sWSDL_URI, array( 'classmap' => array(
> 'StockSymbol' => 'MyClass' )));
>
> $oClient->getStockValue( $oObj );
> ?>
>
> Am I even close?
first off, let me recommend the phpt tests in the php source. for the soap
stuff, you will find them under ext/soap/tests. i was looking through a few
of them. looks like if you have a chunk of wsdl, like this
<xsd:complexType
name="book">
<xsd:all>
<xsd:element name="a"
type="xsd:string"/>
<xsd:element name="b"
type="xsd:string"/>
</xsd:all>
</xsd:complexType>
you can map classes to it like this (which i gather you already got) w/ the
$options param in the SoapClient constructor
class book{
public $a="a";
public $b="c";
}
it looks like you can use contructors too though, im a bit too lazy to hash
out the details as i go through the phpt tests =/ but anyway, instead of
instantiating book ourselves, the SoapClient instance will do that for us,
as in
$sc = new SoapClient(
$someWsdlAddr,
array(
'classmap' => array(
'book' => 'book'
)
)
);
$book = $sc->readBook($myFavBook);
so assuming there was a method defined in the wsdl, roughly like,
<ns1:readBook>
<res xsi:type="ns1:book">
<a xsi:type="xsd:string">Lord of the Rings</a>
<b xsi:type="xsd:string">JRR Token</b>
</res>
</ns1:readBook>
we could then take the book instance the SoapClient created for us, and do
echo "title: {$book->a}, author: {$book->b}"; /// produces "title: Lord of
the Rings, author: JRR Token"
Now, what happens if one of the required arguments
> to the server function is a variable that has a hyphen in it? Is
> there any way I can get around that since PHP doesn't allow you to
> define variables with hyphens?
soo, im guessing the wsdl might be something like
<xsd:complexType
name="book">
<xsd:all>
<xsd:element name="a--"
type="xsd:string"/>
<xsd:element name="b"
type="xsd:string"/>
</xsd:all>
</xsd:complexType>
normally, with variable variables, you could hack around this, as in
$varWHyphen = 'a--';
$$varWHyphen = 5;
however, instance variables cannot be created out of variable variables, so
i doubt thats possible in this context.
* Whether using class/objects to pass parameters to a server function
> (assuming I have the above correct) or arrays, how can you define
> further attributes for each parameter? Is that even possible?
well, i think so. basically, i think this feature is just a way to have the
SoapClient instantiate an object rather than just returning an array. so
the examples in the phpt tests are simple, but you might have a class that
actually has methods and so forth, you just use a soap call to create it.
then you go on your way. this could be a bit more desireable for some folks
than getting an array and using it to create an object themselves, i
suppose.
so for example in the book class above you might have,
public function __toString() {
return "title: {$this->a}, author: {$this->b}";
}
> So
> here is an example of a SOAP message that the server is expecting:
>
> <?xml version="1.0"?>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <soap:Body>
> <ServerFuncName xmlns="urn:/joe/bob/briggs/types">
> <String1>Var1 Value</String1>
> <String2>live</String2>
> <Array1>
> <SubArray1 status="complete">
> <SubArray2 xmlns="" encoding="" node-type="">
> <SubArray3>
> <node name="attribute1">Node Value</node>
> <node name="attribute2">Node Value</node>
> <node name="attribute3">Node Value</node>
> <node name="attribute4">Node Value</node>
> <node name="attribute5">Node Value</node>
> </SubArray3>
> </SubArray2>
> <SubArray2 xmlns="" encoding="" node-type=""></SubArray2>
> </SubArray1>
> </Array1>
> </ServerFuncName>
> </soap:Body>
> </soap:Envelope>
>
> How can I set up the attributes illustrated above? Encoding,
> node-type, etc? Is that possible?
dunno, maybe scope the phpt tests and see if you can figure something out..
i might play around w/ the example later, but as i said im weak on the
actual xml structure of the soap spec.
* Finally, is there a really good and/or comprehensive tutorial and/or
> write-up on PHPs SOAP module? The documentation is pretty spartan and
> what I have found doesn't really go in to much depth.
yea, well, i think we are all in the same boat here. like i said the phpt
tests are your friend here :D
-nathan