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

PHP page for Soap Server (I saw this):

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

But I am missing an important lack of documentation for my own problem:

I need to know if it is possible to instantiate the server directly using an XML string, for example, the SimpleXML class:

 //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 several different URLs that must use the same XML, so I need to perform the on-the-fly replacement at the URL of the template and change it to the right, and then load the WSDL. But I do not want to save the instantly generated WSDL to the HDD to delete it immediately after reading it.

Is it possible to create some kind of โ€œvirtual fileโ€ in PHP and use it as if it were a disk read by one? Some kind of stream buffer? Or some kind of file descriptor on the fly?

+7
source share
1 answer

Yes, itโ€™s possible by creating a DATA URI from the contents of the files and using it as a โ€œ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 are looking for. The answer.

+18
source

All Articles