Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 504
Lightworker Avatar asked Nov 16 '11 12:11

Lightworker


1 Answers

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.

like image 89
hakre Avatar answered Nov 04 '22 15:11

hakre