ff462e5f9ceefac95afd6ca679a017001c67568b
[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          |
40 | ------------- | ------------------ |
41 | xmlrpc_client | PhpXmlRpc\Client   |
42 | xmlrpc_server | PhpXmlRpc\Server   |
43 | xmlrpcmsg     | PhpXmlRpc\Request  |
44 | xmlrpcresp    | PhpXmlRpc\Response |
45 | xmlrpcval     | PhpXmlRpc\Value    |
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 | _xmlrpcs_capabilities    | NOT AVAILABLE YET                           |           |
58 | _xmlrpc_debuginfo        | PhpXmlRpc\Server::$_xmlrpc_debuginfo        | protected |
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
71 | Old function             | New function                                |
72 | ------------------------ | ------------------------------------------- |
73 | ...                      |                                             |
74
75
76 Character sets and encoding
77 ---------------------------
78
79 The default character set used by the library to deliver data to your app is now UTF8.
80 It is also the character set that the library expects data from your app to be in (including method names).
81 The value can be changed (to either US-ASCII or ISO-8859-1) by setting teh desired value to
82     PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding
83
84 Usage of closures for wrapping
85 ------------------------------
86
87 ...
88
89
90 Differences in server behaviour
91 -------------------------------
92
93 The results for calls to system.listMethods and system.getCapabilities can not be set anymore via changes to
94 global variables.
95
96
97 Other
98 -----
99
100 * when serialize() is invoked on a response and its payload can not be serialized, an exception is thrown instead of
101   ending all execution
102
103 * all error messages now mention the class and method which generated name
104
105 * all library source code has been moved to the src/ directory 
106
107 * all source code has been reformatted according to modern PSR standards
108
109
110 Enabling compatibility with legacy code
111 ---------------------------------------
112
113 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
114 replacement, regardless of all of the changes mentioned above.
115
116 The magic happens via the xmlrpc.inc, xmlrpcs.inc and xmlrpc_wrappers.inc files, which have been kept solely for
117 the purpose of backwards compatibility (you might notice that they are still in the 'lib' directory, whereas all of
118 the refactored code now sits in the 'src' directory).
119
120 Of course, some minor changes where inevitable, and backwards compatibility can not be guaranteed at 100%.
121 Below is the list of all known changes and possible pitfalls.
122
123 ### Default character set used for application data
124
125 * when including the xmlrpc.inc file, the defalt character set used by the lib to give data to your app gets switched
126   back to ISO-8859-1, as it was in previous versions
127
128 * 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
129
130         // code as was before
131         include('xmlrpc.inc');
132         $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
133         // new line needed now
134         PhpXmlRpc\PhpXmlRpc::importGlobals();
135
136 ### Usage of global variables
137
138 * ALL global variables which existed after including xmlrpc.inc in version 3 still do exist after including it in v. 4
139  
140 * Code which relies on using (as in 'reading') their value will keep working unchanged
141
142 * Changing the value of some of those variables does not have any effect anymore on library operation.
143   This is true for:
144
145         $GLOBALS['xmlrpcI4']
146         $GLOBALS['xmlrpcInt']
147         $GLOBALS['xmlrpcBoolean']
148         $GLOBALS['xmlrpcDouble']
149         $GLOBALS['xmlrpcString']
150         $GLOBALS['xmlrpcDatetTme']
151         $GLOBALS['xmlrpcBase64']
152         $GLOBALS['xmlrpcArray']
153         $GLOBALS['xmlrpcStruct']
154         $GLOBALS['xmlrpcValue']
155         $GLOBALS['xmlrpcNull']
156         $GLOBALS['xmlrpcTypes']
157         $GLOBALS['xmlrpc_valid_parents']
158         $GLOBALS['xml_iso88591_Entities']
159
160 * Changing the value of the other global variables will still have an effect on operation of the library, but only after
161   a call to PhpXmlRpc::importGlobals()
162
163     Example:
164
165         // code as was before
166         include('xmlrpc.inc');
167         $GLOBALS['xmlrpc_null_apache_encoding'] = true;
168         // new line needed now
169         PhpXmlRpc\PhpXmlRpc::importGlobals();
170         
171     Alternative solution:
172     
173         include('xmlrpc.inc');
174         PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_apache_encoding = true;
175
176 * Not all variables which existed after including xmlrpcs.inc in version 3 are available
177
178     - $GLOBALS['_xmlrpcs_prev_ehandler'] has been replaced with protected static var PhpXmlRpc\Server::$_xmlrpcs_prev_ehandler
179         and is thus not available any more
180
181     - same for $GLOBALS['_xmlrpcs_occurred_errors']
182
183     - same for $GLOBALS['_xmlrpc_debuginfo']
184
185     - $GLOBALS['_xmlrpcs_capabilities'] and $GLOBALS['_xmlrpcs_dmap'] have been removed
186
187 ### Using typeof/class-name checks in your code
188
189 * if you are checking the types of returned objects, your checks will most likely fail.
190   This is due to the fact that 'old' classes extend the 'new' versions, but library code that creates object
191   instances will return the new classes.
192
193     Example:
194         
195         is_a(php_xmlrpc_encode('hello world'), 'xmlrpcval') => false
196         is_a(php_xmlrpc_encode('hello world'), 'PhpXmlRpc\Value') => true
197
198 ### wrapping methods now return closures
199
200 might be fixed later?
201
202 ### server behaviour can not be changed by setting global variables (the ones starting with _xmlrpcs_ )
203
204 might be fixed later?