简体   繁体   中英

PHP Soap Server: instantiate with a string (xml string) instead of WSDL file (url to it)

The PHP page of Soap Server (I've seen it):

http://www.php.net/manual/en/soapserver.soapserver.php

But I'm missing an important lack of documentation there for my very own problem:

I need to know if it's possible to instantiate the Server directly with an XML string, like SimpleXML class does:

//From var (the one I want):
$movies = new SimpleXMLElement($xmlstr);

or

//From file and from string (the one I want):
$xml = simplexml_load_file('test.xml');

$xml = simplexml_load_string($string);

So I would like to do something like this:

$wsdl_cont = file_get_contents("../xmls/mywsdl.wsdl");
$server = new SoapServer($wsdl_cont);

Is it possible?

The reason for this is, because I have some different URLs which have to use the same XML, so I need to do a replace on the fly on a template URL, and change it to the right one and then, load the WSDL. But I don't want to save on HDD the instantly generated WSDL to delete it right after having it read.

Is it possible to create some kind of "virtual file" on PHP and use it like if it was a disk read one? Some kind o stream buffer? Or some kind of file descriptor on the fly?

Yes it's possible by creating a DATA URI out of the files content and use it as "file".

$name = 'mywsdl.wsdl';
$path = '/path-to-file/'.$name;
$data = file_get_contents($path);
$file = 'data://text/plain;base64,'.base64_encode($data);
$server = new SoapServer($file);

This should do what you're looking for. A related answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM