ServerProxy.php 2.4 KB

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