b587d9b0c871b911cb2ce3b07935ba3e6a595382
[plcapi.git] / doc / api_changes_v4.md
1 API Changes between library versions 3 and 4
2 ============================================
3
4 Class loading
5 -------------
6
7 It is not necessary any more to include the files xmlrpc.inc, xmlrpcs.inc and xmlrpc_wrappers.inc to have the
8 library classes available.
9
10 Instead, it is recommended to rely on class autoloading.
11  
12 * If you are using Composer, just install the library by declaring it as dependency for your project in composer.json 
13
14         "require": {
15             ...,
16             "phpxmlrpc/phpxmlrpc": "~4.0"
17         },
18        
19 * If you do not use Composer, an autoloader for the library can be found in src/Atuloader.php.
20   The php example files in the demo/client folder do make use of it.
21   Example code to set up the autoloader:
22     
23         include_once <path to library> . "/src/Autoloader.php";
24         PhpXmlRpc\Autoloader::register();
25
26
27 * If you still include manually xmlrpc.inc, xmlrpcs.inc or xmlrpc_wrappers.inc, you will not need to set up
28   class autoloading, as those files do include all the source files for the library classes
29
30
31 New class naming
32 ----------------
33
34 All classes have ben renamed, are now properly namespaced and follow the CamelCase naming convention.
35 Existing class methods and members have been preserved; all new method names follow camelCase. 
36
37 Conversion table:
38
39 | Old class     | New class          | Notes                                 |
40 | ------------- | ------------------ | ------------------------------------- |
41 | xmlrpc_client | PhpXmlRpc\Client   |                                       |
42 | xmlrpc_server | PhpXmlRpc\Server   | Removed method: echoInput             |
43 | xmlrpcmsg     | PhpXmlRpc\Request  |                                       |
44 | xmlrpcresp    | PhpXmlRpc\Response |                                       |
45 | xmlrpcval     | PhpXmlRpc\Value    | Removed methods: serializeval, getval |
46
47
48 Global variables cleanup
49 ------------------------
50
51 All variables in the global scope have been moved into classes.
52
53 Conversion table:
54
55 | Old variable             | New variable                                | Notes     |
56 | ------------------------ | ------------------------------------------- | --------- |
57 | _xmlrpc_debuginfo        | PhpXmlRpc\Server::$_xmlrpc_debuginfo        | protected |
58 | _xmlrpcs_capabilities    | NOT AVAILABLE YET                           |           |
59 | _xmlrpcs_dmap            | NOT AVAILABLE YET                           |           |
60 | _xmlrpcs_occurred_errors | PhpXmlRpc\Server::$_xmlrpcs_occurred_errors | protected |
61 | _xmlrpcs_prev_ehandler   | PhpXmlRpc\Server::$_xmlrpcs_prev_ehandler   | protected |
62 | xmlrpcWPFObjHolder       | PhpXmlRpc\Wrapper::$objHolder               |           |
63 | ...                      |                                             |           |
64
65
66 Global functions cleanup
67 ------------------------
68
69 Most functions in the global scope have been moved into classes.
70 Some have been slightly changed.
71
72 | Old function                     | New function                                | Notes                                                  |
73 | -------------------------------- | ------------------------------------------- | ------------------------------------------------------ |
74 | build_client_wrapper_code        | none                                        |                                                        |
75 | build_remote_method_wrapper_code | PhpXmlRpc\Wrapper::buildWrapMethodSource    | signature changed                                      |
76 | decode_chunked                   | PhpXmlRpc\Helper\Http::decodeChunked        |                                                        |
77 | guess_encoding                   | PhpXmlRpc\Helper\XMLParser::guessEncoding   |                                                        |
78 | has_encoding                     | PhpXmlRpc\Helper\XMLParser::hasEncoding     |                                                        |
79 | is_valid_charset                 | PhpXmlRpc\Helper\Charset::isValidCharset    |                                                        |
80 | iso8601_decode                   | PhpXmlRpc\Helper\Date::iso8601Decode        |                                                        |
81 | iso8601_encode                   | PhpXmlRpc\Helper\Date::iso8601Encode        |                                                        |
82 | php_2_xmlrpc_type                | PhpXmlRpc\Wrapper::php2XmlrpcType           |                                                        |
83 | php_xmlrpc_decode                | PhpXmlRpc\Encoder::decode                   |                                                        |
84 | php_xmlrpc_decode_xml            | PhpXmlRpc\Encoder::decodeXml                |                                                        |
85 | php_xmlrpc_encode                | PhpXmlRpc\Encoder::encode                   |                                                        |
86 | wrap_php_class                   | PhpXmlRpc\Wrapper::wrapPhpClass             | returns closures instead of function names by default  |
87 | wrap_php_function                | PhpXmlRpc\Wrapper::wrapPhpFunction          | returns closures instead of function names by default  |
88 | wrap_xmlrpc_method               | PhpXmlRpc\Wrapper::wrapXmrlpcMethod         | returns closures instead of function names by default  |
89 | wrap_xmlrpc_server               | PhpXmlRpc\Wrapper::wrapXmrlpcServer         | returns closures instead of function names by default; |
90 |                                  |                                             | returns an array ready for usage in dispatch map       |
91 | xmlrpc_2_php_type                | PhpXmlRpc\Wrapper::Xmlrpc2phpType           |                                                        |
92 | xmlrpc_debugmsg                  | PhpXmlRpc\Server::xmlrpc_debugmsg           |                                                        |
93 | xmlrpc_encode_entitites          | PhpXmlRpc\Helper\Charset::encodeEntitites   |                                                        |
94
95
96 Character sets and encoding
97 ---------------------------
98
99 The default character set used by the library to deliver data to your app is now UTF8.
100 It is also the character set that the library expects data from your app to be in (including method names).
101 The value can be changed (to either US-ASCII or ISO-8859-1) by setting teh desired value to
102     PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding
103
104 Usage of closures for wrapping
105 ------------------------------
106
107 ...
108
109
110 Differences in server behaviour
111 -------------------------------
112
113 The results for calls to system.listMethods and system.getCapabilities can not be set anymore via changes to
114 global variables.
115
116
117 Other
118 -----
119
120 * when serialize() is invoked on a response and its payload can not be serialized, an exception is thrown instead of
121   ending all execution
122
123 * all error messages now mention the class and method which generated name
124
125 * all library source code has been moved to the src/ directory 
126
127 * all source code has been reformatted according to modern PSR standards
128
129
130 Enabling compatibility with legacy code
131 ---------------------------------------
132
133 If you have code which relies on version 3 of the phpxmlrpc API, you *should* be able to use version 4 as a drop-in
134 replacement, regardless of all of the changes mentioned above.
135
136 The magic happens via the xmlrpc.inc, xmlrpcs.inc and xmlrpc_wrappers.inc files, which have been kept solely for
137 the purpose of backwards compatibility (you might notice that they are still in the 'lib' directory, whereas all of
138 the refactored code now sits in the 'src' directory).
139
140 Of course, some minor changes where inevitable, and backwards compatibility can not be guaranteed at 100%.
141 Below is the list of all known changes and possible pitfalls when enabling 'compatibility mode'.
142
143 ### Default character set used for application data
144
145 * when including the xmlrpc.inc file, the defalt character set used by the lib to give data to your app gets switched
146   back to ISO-8859-1, as it was in previous versions
147
148 * if yor app used to change that value, you will need to add one line to your code, to make sure it is properly used
149
150         // code as was before
151         include('xmlrpc.inc');
152         $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
153         // new line needed now
154         PhpXmlRpc\PhpXmlRpc::importGlobals();
155
156 ### Usage of global variables
157
158 * ALL global variables which existed after including xmlrpc.inc in version 3 still do exist after including it in v. 4
159  
160 * Code which relies on using (as in 'reading') their value will keep working unchanged
161
162 * Changing the value of some of those variables does not have any effect anymore on library operation.
163   This is true for:
164
165         $GLOBALS['xmlrpcI4']
166         $GLOBALS['xmlrpcInt']
167         $GLOBALS['xmlrpcBoolean']
168         $GLOBALS['xmlrpcDouble']
169         $GLOBALS['xmlrpcString']
170         $GLOBALS['xmlrpcDatetTme']
171         $GLOBALS['xmlrpcBase64']
172         $GLOBALS['xmlrpcArray']
173         $GLOBALS['xmlrpcStruct']
174         $GLOBALS['xmlrpcValue']
175         $GLOBALS['xmlrpcNull']
176         $GLOBALS['xmlrpcTypes']
177         $GLOBALS['xmlrpc_valid_parents']
178         $GLOBALS['xml_iso88591_Entities']
179
180 * Changing the value of the other global variables will still have an effect on operation of the library, but only after
181   a call to PhpXmlRpc::importGlobals()
182
183     Example:
184
185         // code as was before
186         include('xmlrpc.inc');
187         $GLOBALS['xmlrpc_null_apache_encoding'] = true;
188         // new line needed now
189         PhpXmlRpc\PhpXmlRpc::importGlobals();
190         
191     Alternative solution:
192     
193         include('xmlrpc.inc');
194         PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_apache_encoding = true;
195
196 * Not all variables which existed after including xmlrpcs.inc in version 3 are available
197
198     - $GLOBALS['_xmlrpcs_prev_ehandler'] has been replaced with protected static var PhpXmlRpc\Server::$_xmlrpcs_prev_ehandler
199         and is thus not available any more
200
201     - same for $GLOBALS['_xmlrpcs_occurred_errors']
202
203     - same for $GLOBALS['_xmlrpc_debuginfo']
204
205     - $GLOBALS['_xmlrpcs_capabilities'] and $GLOBALS['_xmlrpcs_dmap'] have been removed
206
207 ### Using typeof/class-name checks in your code
208
209 * if you are checking the types of returned objects, your checks will most likely fail.
210   This is due to the fact that 'old' classes extend the 'new' versions, but library code that creates object
211   instances will return the new classes.
212
213     Example:
214         
215         is_a(php_xmlrpc_encode('hello world'), 'xmlrpcval') => false
216         is_a(php_xmlrpc_encode('hello world'), 'PhpXmlRpc\Value') => true
217
218 ### server behaviour can not be changed by setting global variables (the ones starting with _xmlrpcs_ )
219
220 might be fixed later?