简体   繁体   English

PHP Soap Server:使用字符串(xml字符串)而不是WSDL文件实例化(url to it)

[英]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): Soap Server的PHP页面(我已经看过了):

http://www.php.net/manual/en/soapserver.soapserver.php 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: 我需要知道是否可以使用XML字符串直接实例化服务器,就像SimpleXML类一样:

//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. 原因是,因为我有一些不同的URL必须使用相同的XML,所以我需要在模板URL上动态替换,并将其更改为正确的URL,然后加载WSDL。 But I don't want to save on HDD the instantly generated WSDL to delete it right after having it read. 但我不想在硬盘上保存即时生成的WSDL,以便在读取后立即将其删除。

Is it possible to create some kind of "virtual file" on PHP and use it like if it was a disk read one? 是否有可能在PHP上创建某种“虚拟文件”并使用它,就像它是一个磁盘读取一样? 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". 是的,可以通过从文件内容创建DATA URI并将其用作“文件”。

$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 . 一个相关的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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