Skip to content

Commit cf4092e

Browse files
committed
[WIP] Explanations for a couple more options
1 parent 4ea9708 commit cf4092e

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

reference/soap/soapclient/construct.xml

+82-4
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,17 @@
458458
</term>
459459
<listitem>
460460
<para>
461-
TODO
461+
When decoding a response to an array, the default behaviour is to detect whether
462+
an element name appears once or multiple times in a particular parent element.
463+
For elements which appear only once, an object property allows direct access to
464+
the content; for elements which appear more than once, the property contains an
465+
array with the content of each matching element.
466+
</para>
467+
<para>
468+
If the <constant>SOAP_SINGLE_ELEMENT_ARRAYS</constant> feature is enabled,
469+
elements which appear only once are placed in a single-element array, so that
470+
access is consistent for all elements. This only has an effect when using a WSDL
471+
containing a schema for the response. See Examples sections for an illustration.
462472
</para>
463473
</listitem>
464474
</varlistentry>
@@ -468,7 +478,9 @@
468478
</term>
469479
<listitem>
470480
<para>
471-
TODO
481+
When the <parameter>use</parameter> option is set to <literal>encoded</literal>,
482+
force arrays to use a type of <literal>SOAP-ENC:Array</literal>, rather than a
483+
schema-specific type.
472484
</para>
473485
</listitem>
474486
</varlistentry>
@@ -574,8 +586,7 @@ $client = new SoapClient("some.wsdl", ['context' => $context]);
574586
<para>
575587
<example>
576588
<title>
577-
<function>SoapClient::__construct</function>
578-
example
589+
<function>SoapClient::__construct</function> example
579590
</title>
580591
<programlisting role="php">
581592
<![CDATA[
@@ -623,6 +634,73 @@ $client = new SoapClient("books.wsdl", array('classmap' => array('book' => "MyBo
623634
</programlisting>
624635
</example>
625636
</para>
637+
638+
<para>
639+
<example>
640+
<title>Using the <constant>SOAP_SINGLE_ELEMENT_ARRAYS</constant> feature</title>
641+
<programlisting role="php">
642+
<![CDATA[
643+
/* Assuming a response like this, and an appropriate WSDL:
644+
<?xml version="1.0" encoding="UTF-8"?>
645+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:example">
646+
<SOAP-ENV:Body>
647+
<response>
648+
<collection>
649+
<item>Single</item>
650+
</collection>
651+
<collection>
652+
<item>First</item>
653+
<item>Second</item>
654+
</collection>
655+
</response>
656+
</SOAP-ENV:Body>
657+
</SOAP-ENV:Envelope>
658+
*/
659+
660+
echo "Default:\n";
661+
662+
$client = new TestSoapClient(__DIR__ . '/temp.wsdl');
663+
$response = $client->exampleRequest();
664+
var_dump( $response->collection[0]->item );
665+
var_dump( $response->collection[1]->item );
666+
667+
echo "\nWith SOAP_SINGLE_ELEMENT_ARRAYS:\n";
668+
669+
$client = new TestSoapClient(__DIR__ . '/temp.wsdl', ['features' => SOAP_SINGLE_ELEMENT_ARRAYS]);
670+
$response = $client->exampleRequest();
671+
var_dump( $response->collection[0]->item );
672+
var_dump( $response->collection[1]->item );
673+
]]>
674+
</programlisting>
675+
676+
&example.outputs;
677+
678+
<screen>
679+
<![CDATA[
680+
Default:
681+
string(6) "Single"
682+
array(2) {
683+
[0] =>
684+
string(5) "First"
685+
[1] =>
686+
string(6) "Second"
687+
}
688+
689+
With SOAP_SINGLE_ELEMENT_ARRAYS:
690+
array(1) {
691+
[0] =>
692+
string(6) "Single"
693+
}
694+
array(2) {
695+
[0] =>
696+
string(5) "First"
697+
[1] =>
698+
string(6) "Second"
699+
}
700+
]]>
701+
</screen>
702+
</example>
703+
</para>
626704
</refsect1>
627705

628706
</refentry>

0 commit comments

Comments
 (0)