File: book.xml

package info (click to toggle)
php-doc 20140201-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 74,084 kB
  • ctags: 4,040
  • sloc: xml: 998,137; php: 20,812; cpp: 500; sh: 177; makefile: 63; awk: 28
file content (174 lines) | stat: -rw-r--r-- 5,624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 330340 $ -->
<!-- State: experimental -->
 
<book xml:id="book.sca" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <title>SCA</title>
 
 <!-- {{{ preface -->
 <preface xml:id="intro.sca">
  &reftitle.intro;
  &warn.experimental;
  <para> 
   SCA for PHP makes it possible for a PHP programmer to write
   reusable components, which can be called in a variety of ways, with an
   identical interface and with a minimum of fuss. At present
   components can call each other either locally or via Web services,
   but in the future it is expected that other ways will be possible. It
   provides the programmer with a way of doing this which will look as
   natural as possible in PHP. 
  </para>
  
  <para> 
   SCA components use phpDocumentor-style (see
   http://www.phpdoc.org/) annotations to declare dependencies on
   other SCA components or Web services. The SCA for PHP runtime
   resolves these dependencies at runtime on behalf of the components,
   and thus allows the PHP programmer to focus on the business logic
   rather than on locating and obtaining references to dependencies.
  </para>
  
  <para> 
   The SCA for PHP programming model can be extended to support a
   number of service types, such as REST and Atompub. However, Web
   services (more accurately, WSDL defined, SOAP/HTTP services), are
   the only type currently specified. 
  </para>
  
  <para> 
   Components also use annotations to define the interface which
   they expose as a service. The SCA for PHP runtime will automatically
   generate WSDL from these annotations, so that an SCA component is
   easily exposed as a web service. These annotations are a natural
   extension to those provided by phpDocumentor. Deploying a Web
   service can be as simple as placing a PHP component under the document
   root of a web server. 
  </para>
  
  <para> 
   Components also use annotations to specify data structures
   (expressed using XML schema complex types) which are then handled
   using Service Data Objects (SDOs). 
  </para>
  
  <para> 
   A PHP script which is not an SCA component and which contains no
   annotations can use the services of an SCA component. A PHP script or
   component can make calls to a web service that is not an SCA component,
   but using the same system of calls or annotations to obtain a
   reference.
  </para>

  <para> 
   First we show a single SCA component, ConvertedStockQuote
   which illustrates many of the features of SCA for PHP. It has one
   method,
   <function>getQuote</function>, which given a stock "ticker"
   obtains a price quote for that stock, converted to a given currency.
   We shall be using this example as a basis for explaining the SCA for PHP
   throughout the rest of this document. 
  </para>
  
  <para>
   <example>
    <title> A sample SCA component </title>
     <programlisting role="php">
<![CDATA[
<?php

include "SCA/SCA.php";

/**
 * Calculate a stock price for a given ticker symbol in a given currency.
 *
 * @service
 * @binding.soap
 */
class ConvertedStockQuote {

    /**
     * The currency exchange rate service to use.
     *
     * @reference
     * @binding.php ../ExchangeRate/ExchangeRate.php
     */
    public $exchange_rate;

    /**
     * The stock quote service to use.
     *
     * @reference
     * @binding.soap ../StockQuote/StockQuote.wsdl
     */
    public $stock_quote;

    /**
     * Get a stock quote for a given ticker symbol in a given currency.
     *
     * @param string $ticker The ticker symbol.
     * @param string $currency What currency to convert the value to.
     * @return float The stock value is the target currency.
     */
    function getQuote($ticker, $currency)
    {
        $quote  = $this->stock_quote->getQuote($ticker);
        $rate   = $this->exchange_rate->getRate($currency);
        return  $rate * $quote;
    }
}
?>
]]>
    </programlisting>
   </example>
  </para>
  
  <para> 
   In this example, we see that an SCA component is implemented by a
   script containing a PHP class and includes
   <filename>SCA.php</filename>. The class contains a mixture of
   business logic and references to other components or services. In
   the illustrated
   <function>getQuote</function> method there is only business
   logic, but it relies on the instance variables
   <varname>$stock_quote</varname> and
   <varname>$exchange_rate</varname> having been initialized.
   These refer to two other components and will be initialized by the SCA
   runtime with proxies for these two services, whenever this
   component executes. The annotations for these two services show one
   to be a local component, which will be called within the same PHP
   runtime, and one to be a remote component which will be called via a
   SOAP request. This component also exposes the
   <function>getQuote</function> method both locally and as a web
   service, so it in turn can be called either locally or remotely.
  </para>
 </preface>
 <!-- }}} -->
 
 &reference.sca.setup;
 &reference.sca.constants;
 &reference.sca.examples;
 &reference.sca.reference;

</book>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->