是否可以调用PHP SoapClient构造函数,该构造函数将URL作为参数,而不是字符串的内容。
在我的示例中,我有一个包含WSDL的操作DOMDocument,我将使用saveXML()写入一个字符串。
我的想法是尽可能不触及文件系统。我已经尝试过php:// memory但是测试使用像file_get_contents这样的函数检索流内容会导致空字符串,因为我怀疑流上下文已经消失了。还有另一种方式吗?
答案 0 :(得分:1)
是的,可以使用包含SoapClient
字符串的变量来实例化WSDL
类,所有都不会触及文件系统。由于SoapClient
需要URI参数,因此我们将创建Data URI并将其传递给:
$wsdlstring = <<<WSDL
<?xml version="1.0" encoding="utf-8"?>
<definitions name="SoapArrayTest"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://test-uri/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://test-uri/"
>
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test-uri/">
<complexType name="Baz">
<sequence>
<element name="fruit" type="tns:StringArray"/>
<element name="vegetables" type="tns:StringArray"/>
</sequence>
</complexType>
<element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="BazElement" type="tns:Baz"/>
<complexType name="StringArray">
<sequence>
<element name="item" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="StringArrayElement" type="tns:StringArray"/>
</schema>
</types>
<message name="fooRequest">
</message>
<message name="fooResponse">
<part name="result" type="tns:Baz"/>
</message>
<portType name="TestPortType">
<operation name="foo">
<input message="tns:fooRequest"/>
<output message="tns:fooResponse"/>
</operation>
</portType>
<binding name="TestBinding" type="tns:TestPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="foo">
<soap:operation soapAction="#foo" style="rpc"/>
<input />
<output >
<soap:body parts="result" use="literal" namespace="http://test-uri/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="TestService">
<port name="TestPort" binding="tns:TestBinding">
<soap:address location="http://example.com"/>
</port>
</service>
</definitions>
WSDL;
$doc = new DOMDocument();
$doc->loadXML($wsdlstring);
$data = $doc->saveXML();
$wsdl = 'data://text/plain;base64,'.base64_encode($data);
$soapclient = new SoapClient($wsdl);
var_dump($soapclient->__getFunctions());