Home > Backend Development > PHP Tutorial > SoapDiscoveryclassphp 路虎discovery4 ssdp discovery cancer discovery

SoapDiscoveryclassphp 路虎discovery4 ssdp discovery cancer discovery

WBOY
Release: 2016-07-29 08:53:43
Original
1323 people have browsed it

SoapDiscovery.class.php source code is as follows:

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

<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</span>->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/\" />\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<soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" />\n"<span>;
</span><span> 89</span><span>$serviceWSDL</span> = '<service name="'.<span>$this</span>->service_name."\">\n<documentation />\n<port name=\"".<span>$this</span>->service_name.'Port" binding="tns:'.<span>$this</span>->service_name."Binding\"><soap:address location=\"http://".<span>$_SERVER</span>['SERVER_NAME'].':'.<span>$_SERVER</span>['SERVER_PORT'].<span>$_SERVER</span>['PHP_SELF']."\" />\n</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</span>->getName()."Response\" />\n</operation>\n"<span>;
</span><span> 94</span><span>$bindingWSDL</span>.= '<operation name="'.<span>$method</span>->getName()."\">\n".'<soap:operation soapAction="urn:'.<span>$this</span>->service_name.'#'.<span>$this</span>->class_name.'#'.<span>$method</span>->getName()."\" />\n<input><soap:body use=\"encoded\" namespace=\"urn:<span>$this</span>->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</input>\n<output>\n<soap:body use=\"encoded\" namespace=\"urn:<span>$this</span>->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</output>\n</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\" />\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\" />\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>.= "</portType>\n"<span>;
</span><span>107</span><span>$bindingWSDL</span>.= "</binding>\n"<span>;
</span><span>108</span><span>//</span><span>return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>');</span><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>, '</definitions>'<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<disco:discovery xmlns:disco=\"http://schemas.xmlsoap.org/disco/\" xmlns:scl=\"http://schemas.xmlsoap.org/disco/scl/\">\n<scl:contractRef ref=\"http://".<span>$_SERVER</span>['SERVER_NAME'].':'.<span>$_SERVER</span>['SERVER_PORT'].<span>$_SERVER</span>['PHP_SELF']."?wsdl\" />\n</disco:discovery>"<span>;
</span><span>121</span><span>    }
</span><span>122</span><span>}
</span><span>123</span><span>124</span> ?>
Copy after login

The above has introduced SoapDiscoveryclassphp, including discovery content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template