PageRenderTime 73ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/XmlRpc/Client/ServerIntrospection.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 166 lines | 75 code | 20 blank | 71 comment | 7 complexity | 384c4cbbf74b9e6a45eb075292604b99 MD5 | raw file
  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 Client
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: ServerIntrospection.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * Wraps the XML-RPC system.* introspection methods
  24. *
  25. * @category Zend
  26. * @package Zend_XmlRpc
  27. * @subpackage Client
  28. * @copyright Copyright (c) 2005-2011 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_Client_ServerIntrospection
  32. {
  33. /**
  34. * @var Zend_XmlRpc_Client_ServerProxy
  35. */
  36. private $_system = null;
  37. /**
  38. * @param Zend_XmlRpc_Client $client
  39. */
  40. public function __construct(Zend_XmlRpc_Client $client)
  41. {
  42. $this->_system = $client->getProxy('system');
  43. }
  44. /**
  45. * Returns the signature for each method on the server,
  46. * autodetecting whether system.multicall() is supported and
  47. * using it if so.
  48. *
  49. * @return array
  50. */
  51. public function getSignatureForEachMethod()
  52. {
  53. $methods = $this->listMethods();
  54. require_once 'Zend/XmlRpc/Client/FaultException.php';
  55. try {
  56. $signatures = $this->getSignatureForEachMethodByMulticall($methods);
  57. } catch (Zend_XmlRpc_Client_FaultException $e) {
  58. // degrade to looping
  59. }
  60. if (empty($signatures)) {
  61. $signatures = $this->getSignatureForEachMethodByLooping($methods);
  62. }
  63. return $signatures;
  64. }
  65. /**
  66. * Attempt to get the method signatures in one request via system.multicall().
  67. * This is a boxcar feature of XML-RPC and is found on fewer servers. However,
  68. * can significantly improve performance if present.
  69. *
  70. * @param array $methods
  71. * @return array array(array(return, param, param, param...))
  72. */
  73. public function getSignatureForEachMethodByMulticall($methods = null)
  74. {
  75. if ($methods === null) {
  76. $methods = $this->listMethods();
  77. }
  78. $multicallParams = array();
  79. foreach ($methods as $method) {
  80. $multicallParams[] = array('methodName' => 'system.methodSignature',
  81. 'params' => array($method));
  82. }
  83. $serverSignatures = $this->_system->multicall($multicallParams);
  84. if (! is_array($serverSignatures)) {
  85. $type = gettype($serverSignatures);
  86. $error = "Multicall return is malformed. Expected array, got $type";
  87. require_once 'Zend/XmlRpc/Client/IntrospectException.php';
  88. throw new Zend_XmlRpc_Client_IntrospectException($error);
  89. }
  90. if (count($serverSignatures) != count($methods)) {
  91. $error = 'Bad number of signatures received from multicall';
  92. require_once 'Zend/XmlRpc/Client/IntrospectException.php';
  93. throw new Zend_XmlRpc_Client_IntrospectException($error);
  94. }
  95. // Create a new signatures array with the methods name as keys and the signature as value
  96. $signatures = array();
  97. foreach ($serverSignatures as $i => $signature) {
  98. $signatures[$methods[$i]] = $signature;
  99. }
  100. return $signatures;
  101. }
  102. /**
  103. * Get the method signatures for every method by
  104. * successively calling system.methodSignature
  105. *
  106. * @param array $methods
  107. * @return array
  108. */
  109. public function getSignatureForEachMethodByLooping($methods = null)
  110. {
  111. if ($methods === null) {
  112. $methods = $this->listMethods();
  113. }
  114. $signatures = array();
  115. foreach ($methods as $method) {
  116. $signatures[$method] = $this->getMethodSignature($method);
  117. }
  118. return $signatures;
  119. }
  120. /**
  121. * Call system.methodSignature() for the given method
  122. *
  123. * @param array $method
  124. * @return array array(array(return, param, param, param...))
  125. */
  126. public function getMethodSignature($method)
  127. {
  128. $signature = $this->_system->methodSignature($method);
  129. if (!is_array($signature)) {
  130. $error = 'Invalid signature for method "' . $method . '"';
  131. require_once 'Zend/XmlRpc/Client/IntrospectException.php';
  132. throw new Zend_XmlRpc_Client_IntrospectException($error);
  133. }
  134. return $signature;
  135. }
  136. /**
  137. * Call system.listMethods()
  138. *
  139. * @param array $method
  140. * @return array array(method, method, method...)
  141. */
  142. public function listMethods()
  143. {
  144. return $this->_system->listMethods();
  145. }
  146. }