Rumah > pembangunan bahagian belakang > tutorial php > SoapDiscoveryclassphp 路虎discovery4 ssdp discovery cancer discovery

SoapDiscoveryclassphp 路虎discovery4 ssdp discovery cancer discovery

WBOY
Lepaskan: 2016-07-29 08:53:43
asal
1333 orang telah melayarinya

 SoapDiscovery.class.php 源码如下:

============================================================

<span>  1</span> <span>php
</span><span>  2</span><span>  3</span><span>/*</span><span>*
</span><span>  4</span><span> * Copyright (c) 2005, Braulio Jos?Solano Rojas
</span><span>  5</span><span> * All rights reserved.
</span><span>  6</span><span> * 
</span><span>  7</span><span> * Redistribution and use in source and binary forms, with or without modification, are
</span><span>  8</span><span> * permitted provided that the following conditions are met:
</span><span>  9</span><span> * 
</span><span> 10</span><span> *     Redistributions of source code must retain the above copyright notice, this list of
</span><span> 11</span><span> *     conditions and the following disclaimer. 
</span><span> 12</span><span> *     Redistributions in binary form must reproduce the above copyright notice, this list of
</span><span> 13</span><span> *     conditions and the following disclaimer in the documentation and/or other materials
</span><span> 14</span><span> *     provided with the distribution. 
</span><span> 15</span><span> *     Neither the name of the Solsoft de Costa Rica S.A. nor the names of its contributors may
</span><span> 16</span><span> *     be used to endorse or promote products derived from this software without specific
</span><span> 17</span><span> *     prior written permission.
</span><span> 18</span><span> * 
</span><span> 19</span><span> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
</span><span> 20</span><span> * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
</span><span> 21</span><span> * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
</span><span> 22</span><span> * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
</span><span> 23</span><span> * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
</span><span> 24</span><span> * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
</span><span> 25</span><span> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
</span><span> 26</span><span> * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
</span><span> 27</span><span> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
</span><span> 28</span><span> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
</span><span> 29</span><span> * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
</span><span> 30</span><span> * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
</span><span> 31</span><span> * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span> 32</span><span> * 
</span><span> 33</span><span> *
</span><span> 34</span><span> * @version $Id$
</span><span> 35</span><span> * @copyright 2005 
</span><span> 36</span><span>*/</span><span> 37</span><span> 38</span><span>/*</span><span>*
</span><span> 39</span><span> * SoapDiscovery Class that provides Web Service Definition Language (WSDL).
</span><span> 40</span><span> * 
</span><span> 41</span><span> * @package SoapDiscovery
</span><span> 42</span><span> * @author Braulio Jos?Solano Rojas
</span><span> 43</span><span> * @copyright Copyright (c) 2005 Braulio Jos?Solano Rojas
</span><span> 44</span><span> * @version $Id$
</span><span> 45</span><span> * @access public
</span><span> 46</span><span> *</span><span>*/</span><span> 47</span><span>class</span><span> SoapDiscovery {
</span><span> 48</span><span>private</span><span>$class_name</span> = ''<span>;
</span><span> 49</span><span>private</span><span>$service_name</span> = ''<span>;
</span><span> 50</span><span> 51</span><span>/*</span><span>*
</span><span> 52</span><span>     * SoapDiscovery::__construct() SoapDiscovery class Constructor.
</span><span> 53</span><span>     * 
</span><span> 54</span><span>     * @param string $class_name
</span><span> 55</span><span>     * @param string $service_name
</span><span> 56</span><span>     *</span><span>*/</span><span> 57</span><span>public</span><span>function</span> __construct(<span>$class_name</span> = '', <span>$service_name</span> = ''<span>) {
</span><span> 58</span><span>$this</span>->class_name = <span>$class_name</span><span>;
</span><span> 59</span><span>$this</span>->service_name = <span>$service_name</span><span>;
</span><span> 60</span><span>    }
</span><span> 61</span><span> 62</span><span>/*</span><span>*
</span><span> 63</span><span>     * SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.
</span><span> 64</span><span>     * 
</span><span> 65</span><span>     * @return string
</span><span> 66</span><span>     *</span><span>*/</span><span> 67</span><span>public</span><span>function</span><span> getWSDL() {
</span><span> 68</span><span>if</span> (<span>empty</span>(<span>$this</span>-><span>service_name)) {
</span><span> 69</span><span>throw</span><span>new</span><span>Exception</span>('No service name.'<span>);
</span><span> 70</span><span>        }
</span><span> 71</span><span>$headerWSDL</span> = "<?xml version=\"1.0\" ?>\n"<span>;
</span><span> 72</span><span>$headerWSDL</span>.= "<definitions name='\"<span'>$this->service_name\" targetNamespace=\"urn:<span>$this</span>->service_name\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"urn:<span>$this</span>->service_name\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n"<span>;
</span><span> 73</span><span>$headerWSDL</span>.= "<types xmlns='\"http://schemas.xmlsoap.org/wsdl/\"'></types>\n"<span>;
</span><span> 74</span><span> 75</span><span>if</span> (<span>empty</span>(<span>$this</span>-><span>class_name)) {
</span><span> 76</span><span>throw</span><span>new</span><span>Exception</span>('No class name.'<span>);
</span><span> 77</span><span>        }
</span><span> 78</span><span> 79</span><span>$class</span> = <span>new</span> ReflectionClass(<span>$this</span>-><span>class_name);
</span><span> 80</span><span> 81</span><span>if</span> (!<span>$class</span>-><span>isInstantiable()) {
</span><span> 82</span><span>throw</span><span>new</span><span>Exception</span>('Class is not instantiable.'<span>);
</span><span> 83</span><span>        }
</span><span> 84</span><span> 85</span><span>$methods</span> = <span>$class</span>-><span>getMethods();
</span><span> 86</span><span> 87</span><span>$portTypeWSDL</span> = '<porttype name="'.<span>$this</span>->service_name.'Port">'<span>;
</span><span> 88</span><span>$bindingWSDL</span> = '<binding name="'.<span>$this</span>->service_name.'Binding" type="tns:'.<span>$this</span>->service_name." port>\n<binding style='\"rpc\"' transport='\"http://schemas.xmlsoap.org/soap/http\"'></binding>\n"<span>;
</span><span> 89</span><span>$serviceWSDL</span> = '<service name="'.<span>$this</span>->service_name.">\n<documentation></documentation>\n<port name='\"".<span'>$this->service_name.'Port" binding="tns:'.<span>$this</span>->service_name."Binding\"><address location='\"http://".<span'>$_SERVER['SERVER_NAME'].':'.<span>$_SERVER</span>['SERVER_PORT'].<span>$_SERVER</span>['PHP_SELF']."\" />\n</address></port>\n</service>\n"<span>;
</span><span> 90</span><span>$messageWSDL</span> = ''<span>;
</span><span> 91</span><span>foreach</span> (<span>$methods</span><span>as</span><span>$method</span><span>) {
</span><span> 92</span><span>if</span> (<span>$method</span>->isPublic() && !<span>$method</span>-><span>isConstructor()) {
</span><span> 93</span><span>$portTypeWSDL</span>.= '<operation name="'.<span>$method</span>->getName().">\n".'<input message="tns:'.<span>$method</span>->getName()." request>\n<output message='\"tns:".<span'>$method->getName()."Response\" />\n</output></operation>\n"<span>;
</span><span> 94</span><span>$bindingWSDL</span>.= '<operation name="'.<span>$method</span>->getName().">\n".'<operation soapaction="urn:'.<span>$this</span>->service_name.'#'.<span>$this</span>->class_name.'#'.<span>$method</span>->getName()."></operation>\n<input><body use='\"encoded\"' namespace='\"urn:<span'>$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n\n<output>\n<body use='\"encoded\"' namespace='\"urn:<span'>$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</body></output>\n</body></operation>\n"<span>;
</span><span> 95</span><span>$messageWSDL</span>.= '<message name="'.<span>$method</span>->getName()." request>\n"<span>;
</span><span> 96</span><span>$parameters</span> = <span>$method</span>-><span>getParameters();
</span><span> 97</span><span>foreach</span> (<span>$parameters</span><span>as</span><span>$parameter</span><span>) {
</span><span> 98</span><span>$messageWSDL</span>.= '<part name="'.<span>$parameter</span>->getName()." type='\"xsd:string\"'></part>\n"<span>;
</span><span> 99</span><span>                }
</span><span>100</span><span>$messageWSDL</span>.= "</message>\n"<span>;
</span><span>101</span><span>$messageWSDL</span>.= '<message name="'.<span>$method</span>->getName()." response>\n"<span>;
</span><span>102</span><span>$messageWSDL</span>.= '<part name="'.<span>$method</span>->getName()." type='\"xsd:string\"'></part>\n"<span>;
</span><span>103</span><span>$messageWSDL</span>.= "</message>\n"<span>;
</span><span>104</span><span>            }
</span><span>105</span><span>        }
</span><span>106</span><span>$portTypeWSDL</span>.= "</binding></porttype>\n"<span>;
</span><span>107</span><span>$bindingWSDL</span>.= "\n"<span>;
</span><span>108</span><span>//</span><span>return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</span></definitions>');<span>109</span><span>110</span><span>$fso</span> = <span>fopen</span>(<span>$this</span>->class_name . ".wsdl", "w"<span>);
</span><span>111</span><span>fwrite</span>(<span>$fso</span>, <span>sprintf</span>('%s%s%s%s%s%s', <span>$headerWSDL</span>, <span>$portTypeWSDL</span>, <span>$bindingWSDL</span>, <span>$serviceWSDL</span>, <span>$messageWSDL</span>, ''<span>));
</span><span>112</span><span>    }
</span><span>113</span><span>114</span><span>/*</span><span>*
</span><span>115</span><span>     * SoapDiscovery::getDiscovery() Returns discovery of WSDL.
</span><span>116</span><span>     * 
</span><span>117</span><span>     * @return string
</span><span>118</span><span>     *</span><span>*/</span><span>119</span><span>public</span><span>function</span><span> getDiscovery() {
</span><span>120</span><span>return</span> "<?xml version=\"1.0\" ?>\n<discovery xmlns:disco='\"http://schemas.xmlsoap.org/disco/\"' xmlns:scl='\"http://schemas.xmlsoap.org/disco/scl/\"'>\n<contractref ref='\"http://".<span'>$_SERVER['SERVER_NAME'].':'.<span>$_SERVER</span>['SERVER_PORT'].<span>$_SERVER</span>['PHP_SELF']."?wsdl\" />\n</contractref></discovery>"<span>;
</span><span>121</span><span>    }
</span><span>122</span><span>}
</span><span>123</span><span>124</span> ?>
Salin selepas log masuk

以上就介绍了SoapDiscoveryclassphp,包括了discovery方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan