| 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 Gonalves 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: Value.php 295362 2010-02-22 07:17:31Z clockwerx $
|
|
|
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 'XML/RPC2/Backend.php';
|
|
|
45 |
// }}}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* XML_RPC value class for the XMLRPCext backend.
|
|
|
49 |
*
|
|
|
50 |
* @category XML
|
|
|
51 |
* @package XML_RPC2
|
|
|
52 |
* @author Sergio Carvalho <sergio.carvalho@portugalmail.com>
|
|
|
53 |
* @copyright 2004-2006 Sergio Carvalho
|
|
|
54 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
|
|
55 |
* @link http://pear.php.net/package/XML_RPC2
|
|
|
56 |
*/
|
|
|
57 |
class XML_RPC2_Backend_Xmlrpcext_Value
|
|
|
58 |
{
|
|
|
59 |
|
|
|
60 |
// {{{ createFromNative()
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Factory method that constructs the appropriate XML-RPC encoded type value
|
|
|
64 |
*
|
|
|
65 |
* @param mixed Value to be encode
|
|
|
66 |
* @param string Explicit XML-RPC type as enumerated in the XML-RPC spec (defaults to automatically selected type)
|
|
|
67 |
* @return mixed The encoded value
|
|
|
68 |
*/
|
|
|
69 |
public static function createFromNative($value, $explicitType)
|
|
|
70 |
{
|
|
|
71 |
$type = strtolower($explicitType);
|
|
|
72 |
$availableTypes = array('datetime', 'base64', 'struct');
|
|
|
73 |
if (in_array($type, $availableTypes)) {
|
|
|
74 |
if ($type=='struct') {
|
|
|
75 |
if (!(is_array($value))) {
|
|
|
76 |
throw new XML_RPC2_Exception('With struct type, value has to be an array');
|
|
|
77 |
}
|
|
|
78 |
// Because of http://bugs.php.net/bug.php?id=21949
|
|
|
79 |
// is some cases (structs with numeric indexes), we need to be able to force the "struct" type
|
|
|
80 |
// (xmlrpc_set_type doesn't help for this, so we need this ugly hack)
|
|
|
81 |
$new = array();
|
|
|
82 |
while (list($k, $v) = each($value)) {
|
|
|
83 |
$new["xml_rpc2_ugly_struct_hack_$k"] = $v;
|
|
|
84 |
// with this "string" prefix, we are sure that the array will be seen as a "struct"
|
|
|
85 |
}
|
|
|
86 |
return $new;
|
|
|
87 |
}
|
|
|
88 |
$value2 = (string) $value;
|
|
|
89 |
if (!xmlrpc_set_type($value2, $type)) {
|
|
|
90 |
throw new XML_RPC2_Exception('Error returned from xmlrpc_set_type');
|
|
|
91 |
}
|
|
|
92 |
return $value2;
|
|
|
93 |
}
|
|
|
94 |
return $value;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
// }}}
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
?>
|