ServerProxy.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * The namespace decorator enables object chaining to permit
  23. * calling XML-RPC namespaced functions like "foo.bar.baz()"
  24. * as "$remote->foo->bar->baz()".
  25. *
  26. * @category Zend
  27. * @package Zend_XmlRpc
  28. * @subpackage Client
  29. * @copyright Copyright (c) 2005-2009 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_Client_ServerProxy
  33. {
  34. /**
  35. * @var Zend_XmlRpc_Client
  36. */
  37. private $_client = null;
  38. /**
  39. * @var string
  40. */
  41. private $_namespace = '';
  42. /**
  43. * @var array of Zend_XmlRpc_Client_ServerProxy
  44. */
  45. private $_cache = array();
  46. /**
  47. * Class constructor
  48. *
  49. * @param string $namespace
  50. * @param Zend_XmlRpc_Client $client
  51. */
  52. public function __construct($client, $namespace = '')
  53. {
  54. $this->_namespace = $namespace;
  55. $this->_client = $client;
  56. }
  57. /**
  58. * Get the next successive namespace
  59. *
  60. * @param string $name
  61. * @return Zend_XmlRpc_Client_ServerProxy
  62. */
  63. public function __get($namespace)
  64. {
  65. $namespace = ltrim("$this->_namespace.$namespace", '.');
  66. if (!isset($this->_cache[$namespace])) {
  67. $this->_cache[$namespace] = new $this($this->_client, $namespace);
  68. }
  69. return $this->_cache[$namespace];
  70. }
  71. /**
  72. * Call a method in this namespace.
  73. *
  74. * @param string $methodN
  75. * @param array $args
  76. * @return mixed
  77. */
  78. public function __call($method, $args)
  79. {
  80. $method = ltrim("$this->_namespace.$method", '.');
  81. return $this->_client->call($method, $args);
  82. }
  83. }