sca.examples.structures.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 244 行 · 第 1/2 页
HTML
244 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Working with Data Structures</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="SCA.examples.understanding-wsdl.html">Understanding how the WSDL is generated</a></div> <div class="next" style="text-align: right; float: right;"><a href="SCA.examples.errorhandling.html">Error handling</a></div> <div class="up"><a href="sca.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="SCA.examples.structures" class="section"> <h2 class="title"> Working with Data Structures </h2> <p class="para"> SCA components can pass and return the four PHP scalar types boolean, integer, float and string, but to pass or return data structures, SCA components use Service Data Objects (SDOs). SDOs are described in much more detail in <a href="ref.sdo.html" class="link">the SDO pages</a> of this manual. Readers familiar with SDOs will know that they are suitable for representing the sort of structured and semi-structured data that is frequently modeled in XML, and that they serialize very naturally for passing between remote components, or in Web services. SDOs are presently the only supported way to pass and return data structures. It is not possible to pass or return PHP objects, or PHP arrays. </p> <p class="para"> The SCA runtime always assures data is passed by-value, even for local calls. To do this, the SCA runtime copies any SDOs in the parameter list before passing them on, just as it does for scalar types. </p> <div id="sca.examples.structures.defined" class="section"> <h2 class="title"> How data structures are defined to SCA components </h2> <p class="para"> Currently the only mechanism for specifying the location of a data structure definition is by specifying the types in an XML schema file. However, in the future it may be possible to define types in other ways, such as based on PHP classes or interfaces, or based on definitions expressed as associative arrays. </p> <p class="para"> To illustrate the use of SDOs we introduce a new component. The PortfolioMangement service below returns an SDO representing a stock portfolio for a given customer. </p> <p class="para"> <div class="example"> <p><b>Example #1 A Component that uses Data Structures</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">include </span><span style="color: #DD0000">"SCA/SCA.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/**<br /> * Manage the portfolio for a customer.<br /> *<br /> * @service<br /> * @binding.soap<br /> *<br /> * @types http://www.example.org/Portfolio PortfolioTypes.xsd<br /> *<br /> */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">PortfolioManagement </span><span style="color: #007700">{<br /><br /> </span><span style="color: #FF8000">/**<br /> * Get the stock portfolio for a given customer.<br /> *<br /> * @param integer $customer_id The id for the customer<br /> * @return Portfolio http://www.example.org/Portfolio The stock portfolio (symbols and quantities)<br /> */<br /> </span><span style="color: #007700">function </span><span style="color: #0000BB">getPortfolio</span><span style="color: #007700">(</span><span style="color: #0000BB">$customer_id</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// Pretend we just got this from a database<br /> </span><span style="color: #0000BB">$portfolio </span><span style="color: #007700">= </span><span style="color: #0000BB">SCA</span><span style="color: #007700">::</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.org/Portfolio'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Portfolio'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$holding </span><span style="color: #007700">= </span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">-></span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'holding'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$holding</span><span style="color: #007700">-></span><span style="color: #0000BB">ticker </span><span style="color: #007700">= </span><span style="color: #DD0000">'AAPL'</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$holding</span><span style="color: #007700">-></span><span style="color: #0000BB">number </span><span style="color: #007700">= </span><span style="color: #0000BB">100.5</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$holding </span><span style="color: #007700">= </span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">-></span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'holding'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$holding</span><span style="color: #007700">-></span><span style="color: #0000BB">ticker </span><span style="color: #007700">= </span><span style="color: #DD0000">'INTL'</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$holding</span><span style="color: #007700">-></span><span style="color: #0000BB">number </span><span style="color: #007700">= </span><span style="color: #0000BB">100.5</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$holding </span><span style="color: #007700">= </span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">-></span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'holding'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$holding</span><span style="color: #007700">-></span><span style="color: #0000BB">ticker </span><span style="color: #007700">= </span><span style="color: #DD0000">'IBM'</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$holding</span><span style="color: #007700">-></span><span style="color: #0000BB">number </span><span style="color: #007700">= </span><span style="color: #0000BB">100.5</span><span style="color: #007700">;<br /> return </span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">;<br /> }<br /><br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> The @types annotation: </p> <p class="para"> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">@</span><span style="color: #0000BB">types http</span><span style="color: #007700">:</span><span style="color: #FF8000">//www.example.org/Portfolio PortfolioTypes.xsd<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </p> <p class="para"> indicates that types in the namespace http://www.example.org/Portfolio will be found in the schema file located by the URI PortfolioTypes.xsd. The generated WSDL would reproduce this information with an import statement as follows: </p> <p class="para"> <div class="example-contents"><div class="cdata"><pre> <xs:import schemaLocation="PortfolioTypes.xsd" namespace="http://www.example.org/Portfolio"/></pre></div> </div> </p> <p class="para"> so the URI, absolute or relative, must be one that can be resolved when included in the schemaLocation attribute. </p> </div> <div id="sca.examples.structures.creating" class="section"> <h2 class="title">Creating SDOs </h2> <p class="para"> Readers familiar with SDOs will know that they are always created according to a description of the permitted structure (sometimes referred to as the 'schema' or 'model') and that, rather than creating them directly using 'new', some form of data factory is needed. Often, an existing data object can be used as the data factory, but sometimes, and especially in order to get the first data object, something else must act as the data factory. </p> <p class="para"> In SCA, either the SCA runtime class or the proxies for services, whether local or remote, can act as the data factories for SDOs. The choice of which to use, and when, is described in the next two sections. </p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?