~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/XmlRpc/Server/System.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_XmlRpc
 
17
 * @subpackage Server
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 * @version    $Id$
 
21
 */
 
22
 
 
23
/**
 
24
 * XML-RPC system.* methods
 
25
 *
 
26
 * @category   Zend
 
27
 * @package    Zend_XmlRpc
 
28
 * @subpackage Server
 
29
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
30
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
31
 */
 
32
class Zend_XmlRpc_Server_System
 
33
{
 
34
    /**
 
35
     * Constructor
 
36
     * 
 
37
     * @param  Zend_XmlRpc_Server $server 
 
38
     * @return void
 
39
     */
 
40
    public function __construct(Zend_XmlRpc_Server $server)
 
41
    {
 
42
        $this->_server = $server;
 
43
    }
 
44
 
 
45
    /**
 
46
     * List all available XMLRPC methods
 
47
     *
 
48
     * Returns an array of methods.
 
49
     *
 
50
     * @return array
 
51
     */
 
52
    public function listMethods()
 
53
    {
 
54
        $table = $this->_server->getDispatchTable()->getMethods();
 
55
        return array_keys($table);
 
56
    }
 
57
 
 
58
    /**
 
59
     * Display help message for an XMLRPC method
 
60
     *
 
61
     * @param string $method
 
62
     * @return string
 
63
     */
 
64
    public function methodHelp($method)
 
65
    {
 
66
        $table = $this->_server->getDispatchTable();
 
67
        if (!$table->hasMethod($method)) {
 
68
            throw new Zend_Server_Exception('Method "' . $method . '"does not exist', 640);
 
69
        }
 
70
 
 
71
        return $table->getMethod($method)->getMethodHelp();
 
72
    }
 
73
 
 
74
    /**
 
75
     * Return a method signature
 
76
     *
 
77
     * @param string $method
 
78
     * @return array
 
79
     */
 
80
    public function methodSignature($method)
 
81
    {
 
82
        $table = $this->_server->getDispatchTable();
 
83
        if (!$table->hasMethod($method)) {
 
84
            throw new Zend_Server_Exception('Method "' . $method . '"does not exist', 640);
 
85
        }
 
86
        $method = $table->getMethod($method)->toArray();
 
87
        return $method['prototypes'];
 
88
    }
 
89
 
 
90
    /**
 
91
     * Multicall - boxcar feature of XML-RPC for calling multiple methods
 
92
     * in a single request.
 
93
     *
 
94
     * Expects a an array of structs representing method calls, each element
 
95
     * having the keys:
 
96
     * - methodName
 
97
     * - params
 
98
     *
 
99
     * Returns an array of responses, one for each method called, with the value
 
100
     * returned by the method. If an error occurs for a given method, returns a
 
101
     * struct with a fault response.
 
102
     *
 
103
     * @see http://www.xmlrpc.com/discuss/msgReader$1208
 
104
     * @param  array $methods
 
105
     * @return array
 
106
     */
 
107
    public function multicall($methods)
 
108
    {
 
109
        $responses = array();
 
110
        foreach ($methods as $method) {
 
111
            $fault = false;
 
112
            if (!is_array($method)) {
 
113
                $fault = $this->_server->fault('system.multicall expects each method to be a struct', 601);
 
114
            } elseif (!isset($method['methodName'])) {
 
115
                $fault = $this->_server->fault('Missing methodName: ' . var_export($methods, 1), 602);
 
116
            } elseif (!isset($method['params'])) {
 
117
                $fault = $this->_server->fault('Missing params', 603);
 
118
            } elseif (!is_array($method['params'])) {
 
119
                $fault = $this->_server->fault('Params must be an array', 604);
 
120
            } else {
 
121
                if ('system.multicall' == $method['methodName']) {
 
122
                    // don't allow recursive calls to multicall
 
123
                    $fault = $this->_server->fault('Recursive system.multicall forbidden', 605);
 
124
                }
 
125
            }
 
126
 
 
127
            if (!$fault) {
 
128
                try {
 
129
                    $request = new Zend_XmlRpc_Request();
 
130
                    $request->setMethod($method['methodName']);
 
131
                    $request->setParams($method['params']);
 
132
                    $response = $this->_server->handle($request);
 
133
                    $responses[] = $response->getReturnValue();
 
134
                } catch (Exception $e) {
 
135
                    $fault = $this->_server->fault($e);
 
136
                }
 
137
            }
 
138
 
 
139
            if ($fault) {
 
140
                $responses[] = array(
 
141
                    'faultCode'   => $fault->getCode(),
 
142
                    'faultString' => $fault->getMessage()
 
143
                );
 
144
            }
 
145
        }
 
146
 
 
147
        return $responses;
 
148
    }
 
149
}