Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
4
 
5
// LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{
6
 
7
/**
8
* +-----------------------------------------------------------------------------+
9
* | Copyright (c) 2004-2006 Sergio Goncalves Carvalho                                |
10
* +-----------------------------------------------------------------------------+
11
* | This file is part of XML_RPC2.                                              |
12
* |                                                                             |
13
* | XML_RPC2 is free software; you can redistribute it and/or modify            |
14
* | it under the terms of the GNU Lesser General Public License as published by |
15
* | the Free Software Foundation; either version 2.1 of the License, or         |
16
* | (at your option) any later version.                                         |
17
* |                                                                             |
18
* | XML_RPC2 is distributed in the hope that it will be useful,                 |
19
* | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
20
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
21
* | GNU Lesser General Public License for more details.                         |
22
* |                                                                             |
23
* | You should have received a copy of the GNU Lesser General Public License    |
24
* | along with XML_RPC2; if not, write to the Free Software                     |
25
* | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA                    |
26
* | 02111-1307 USA                                                              |
27
* +-----------------------------------------------------------------------------+
28
* | Author: Sergio Carvalho <sergio.carvalho@portugalmail.com>                  |
29
* +-----------------------------------------------------------------------------+
30
*
31
* @category   XML
32
* @package    XML_RPC2
33
* @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>
34
* @copyright  2004-2006 Sergio Carvalho
35
* @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
36
* @version    CVS: $Id: Backend.php 308634 2011-02-24 19:13:56Z sergiosgc $
37
* @link       http://pear.php.net/package/XML_RPC2
38
*/
39
 
40
// }}}
41
 
42
// dependencies {{{
43
require_once 'XML/RPC2/Exception.php';
44
require_once 'PEAR.php';
45
// }}}
46
 
47
/**
48
 * XML_RPC Backend class. The backend is responsible for the actual execution of
49
 * a request, as well as payload encoding and decoding.
50
 *
51
 * The only external usage of this class is when explicitely setting the backend, as in
52
 * <code>
53
 *  XML_RPC2_Backend::setBackend('php');
54
 *  // or
55
 *  XML_RPC2_Backend::setBackend('xmlrpcext');
56
 * </code>
57
 * Note that if you do not explicitely set the backend, it will be selected automatically.
58
 *
59
 * Internally, this class provides methods to obtain the relevant backend classes:
60
 *  - The server class
61
 *  - The client class
62
 *  - The value class
63
 *
64
 * @category   XML
65
 * @package    XML_RPC2
66
 * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>
67
 * @copyright  2004-2006 Sergio Carvalho
68
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
69
 * @link       http://pear.php.net/package/XML_RPC2
70
 */
71
abstract class XML_RPC2_Backend
72
{
73
 
74
    // {{{ properties
75
 
76
    /**
77
     * current backend
78
     *
79
     * @var string
80
     */
81
    protected static $currentBackend;
82
 
83
    // }}}
84
    // {{{ setBackend()
85
 
86
    /**
87
     * Backend setter.
88
     *
89
     * Currently, two backends exist: 'php' and 'XMLRPCext'.
90
     * The PHP backend has no external dependencies, while the xmlrpcext
91
     * requires the xmlrpc extension.
92
     *
93
     * The XMLRPCext backend is quite faster, and will be automatically
94
     * selected when no explicit backend has been set and the extension
95
     * is available.
96
     *
97
     * @param string The backend to select. Either 'php' or 'XMLRPCext'.
98
     */
99
    public static function setBackend($backend)
100
    {
101
        $backend = ucfirst(strtolower($backend));
102
        if (
103
            $backend != 'Php' &&
104
            $backend != 'Xmlrpcext'
105
           ) {
106
            throw new XML_RPC2_Exception(sprintf('Backend %s does not exist', $backend));
107
        }
108
        if (
109
            $backend == 'Xmlrpcext' &&
110
            !function_exists('xmlrpc_server_create') &&
111
            !( PEAR::loadExtension('php_xmlrpc') )
112
           ) {
113
            throw new XML_RPC2_Exception('Unable to load xmlrpc extension.');
114
        }
115
        self::$currentBackend = $backend;
116
    }
117
 
118
    // }}}
119
    // {{{ getBackend()
120
 
121
    /**
122
     * Backend getter.
123
     *
124
     * Return the current backend name. If no backend was previously selected
125
     * select one and set it.
126
     *
127
     * The xmlrpcext backend is preferred, and will be automatically
128
     * selected when no explicit backend has been set and the xmlrpc
129
     * extension exists. If it does not exist, then the php backend is
130
     * selected.
131
     *
132
     * @return string The current backend
133
     */
134
    protected static function getBackend()
135
    {
136
        if (!isset(self::$currentBackend)) {
137
            try {
138
                self::setBackend('XMLRPCext'); // We prefer this one
139
            } catch (XML_RPC2_Exception $e) {
140
                // TODO According to PEAR CG logging should occur here
141
                self::setBackend('php');     // But will settle with this one in case of error
142
            }
143
        }
144
        return self::$currentBackend;
145
    }
146
 
147
    // }}}
148
    // {{{ getServerClassname()
149
 
150
    /**
151
     * Include the relevant php files for the server class, and return the backend server
152
     * class name.
153
     *
154
     * @return string The Server class name
155
     */
156
    public static function getServerClassname() {
157
        require_once(sprintf('XML/RPC2/Backend/%s/Server.php', self::getBackend()));
158
        return sprintf('XML_RPC2_Backend_%s_Server', self::getBackend());
159
    }
160
 
161
    // }}}
162
    // {{{ getClientClassname()
163
 
164
    /**
165
     * Include the relevant php files for the client class, and return the backend client
166
     * class name.
167
     *
168
     * @return string The Client class name
169
     */
170
    public static function getClientClassname() {
171
        require_once(sprintf('XML/RPC2/Backend/%s/Client.php', self::getBackend()));
172
        return sprintf('XML_RPC2_Backend_%s_Client', self::getBackend());
173
    }
174
 
175
    // }}}
176
    // {{{ getValueClassname()
177
 
178
    /**
179
     * Include the relevant php files for the value class, and return the backend value
180
     * class name.
181
     *
182
     * @return string The Value class name
183
     */
184
    public static function getValueClassname() {
185
        require_once(sprintf('XML/RPC2/Backend/%s/Value.php', self::getBackend()));
186
        return sprintf('XML_RPC2_Backend_%s_Value', self::getBackend());
187
    }
188
 
189
    // }}}
190
 
191
}