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">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"SCA/SCA.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;Manage&nbsp;the&nbsp;portfolio&nbsp;for&nbsp;a&nbsp;customer.<br />&nbsp;*<br />&nbsp;*&nbsp;@service<br />&nbsp;*&nbsp;@binding.soap<br />&nbsp;*<br />&nbsp;*&nbsp;@types&nbsp;http://www.example.org/Portfolio&nbsp;PortfolioTypes.xsd<br />&nbsp;*<br />&nbsp;*/<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">PortfolioManagement&nbsp;</span><span style="color: #007700">{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Get&nbsp;the&nbsp;stock&nbsp;portfolio&nbsp;for&nbsp;a&nbsp;given&nbsp;customer.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;integer&nbsp;$customer_id&nbsp;The&nbsp;id&nbsp;for&nbsp;the&nbsp;customer<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;Portfolio&nbsp;http://www.example.org/Portfolio&nbsp;The&nbsp;stock&nbsp;portfolio&nbsp;(symbols&nbsp;and&nbsp;quantities)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">getPortfolio</span><span style="color: #007700">(</span><span style="color: #0000BB">$customer_id</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Pretend&nbsp;we&nbsp;just&nbsp;got&nbsp;this&nbsp;from&nbsp;a&nbsp;database<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$portfolio&nbsp;</span><span style="color: #007700">=&nbsp;</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">,&nbsp;</span><span style="color: #DD0000">'Portfolio'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'holding'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ticker&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'AAPL'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">number&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">100.5</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'holding'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ticker&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'INTL'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">number&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">100.5</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'holding'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ticker&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'IBM'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$holding</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">number&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">100.5</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$portfolio</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}<br /></span><span style="color: #0000BB">?&gt;</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">&lt;?php<br /></span><span style="color: #007700">@</span><span style="color: #0000BB">types&nbsp;http</span><span style="color: #007700">:</span><span style="color: #FF8000">//www.example.org/Portfolio&nbsp;PortfolioTypes.xsd<br /></span><span style="color: #0000BB">?&gt;</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>   &lt;xs:import schemaLocation=&quot;PortfolioTypes.xsd&quot;                      namespace=&quot;http://www.example.org/Portfolio&quot;/&gt;</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 &#039;schema&#039; or &#039;model&#039;) and that,    rather than creating them directly using &#039;new&#039;, 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 + -
显示快捷键?