Magento file: lib/Zend/XmlRpc/Server/System.php

Please LogIn to Reply!

Post By: admin | 26-01-2012 06:35 Reply

Magento folder: lib/Zend/XmlRpc/Server/
Magento file: lib/Zend/XmlRpc/Server/System.php

  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: System.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. /**
  23. * XML-RPC system.* methods
  24. *
  25. * @category Zend
  26. * @package Zend_XmlRpc
  27. * @subpackage Server
  28. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_XmlRpc_Server_System
  32. {
  33. /**
  34. * @var Zend_XmlRpc_Server
  35. */
  36. protected $_server;
  37. /**
  38. * Constructor
  39. *
  40. * @param Zend_XmlRpc_Server $server
  41. * @return void
  42. */
  43. public function __construct(Zend_XmlRpc_Server $server)
  44. {
  45. $this->_server = $server;
  46. }
  47. /**
  48. * List all available XMLRPC methods
  49. *
  50. * Returns an array of methods.
  51. *
  52. * @return array
  53. */
  54. public function listMethods()
  55. {
  56. $table = $this->_server->getDispatchTable()->getMethods();
  57. return array_keys($table);
  58. }
  59. /**
  60. * Display help message for an XMLRPC method
  61. *
  62. * @param string $method
  63. * @return string
  64. */
  65. public function methodHelp($method)
  66. {
  67. $table = $this->_server->getDispatchTable();
  68. if (!$table->hasMethod($method)) {
  69. #require_once 'Zend/XmlRpc/Server/Exception.php';
  70. throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
  71. }
  72. return $table->getMethod($method)->getMethodHelp();
  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. #require_once 'Zend/XmlRpc/Server/Exception.php';
  85. throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
  86. }
  87. $method = $table->getMethod($method)->toArray();
  88. return $method['prototypes'];
  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. if (!$fault) {
  127. try {
  128. $request = new Zend_XmlRpc_Request();
  129. $request->setMethod($method['methodName']);
  130. $request->setParams($method['params']);
  131. $response = $this->_server->handle($request);
  132. if ($response instanceof Zend_XmlRpc_Fault
  133. || $response->isFault()
  134. ) {
  135. $fault = $response;
  136. } else {
  137. $responses[] = $response->getReturnValue();
  138. }
  139. } catch (Exception $e) {
  140. $fault = $this->_server->fault($e);
  141. }
  142. }
  143. if ($fault) {
  144. $responses[] = array(
  145. 'faultCode' => $fault->getCode(),
  146. 'faultString' => $fault->getMessage()
  147. );
  148. }
  149. }
  150. return $responses;
  151. }
  152. }
`Reply Or Comment!
Please LogIn to Reply!