You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.9 KiB

  1. <?php
  2. /*
  3. This file is part of ActiveLink PHP XML Package (www.active-link.com).
  4. Copyright (c) 2002-2004 by Zurab Davitiani
  5. You can contact the author of this software via E-mail at
  6. hattrick@mailcan.com
  7. ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as published by
  9. the Free Software Foundation; either version 2.1 of the License, or
  10. (at your option) any later version.
  11. ActiveLink PHP XML Package is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with ActiveLink PHP XML Package; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. /*
  20. * requires HTTPClient, XML and XMLDocument classes
  21. */
  22. import("org.active-link.net.HTTPClient");
  23. import("org.active-link.xml.XML");
  24. import("org.active-link.xml.XMLDocument");
  25. /**
  26. * XMLRPCClient class provides XML-RPC client capabilities
  27. * @class XMLRPCClient
  28. * @package org.active-link.xml
  29. * @author Zurab Davitiani
  30. * @version 0.4.0
  31. * @extends HTTPClient
  32. * @requires HTTPClient, XML, XMLDocument
  33. * @see HTTPClient
  34. */
  35. class XMLRPCClient extends HTTPClient {
  36. var $xml;
  37. var $xmlDoc;
  38. var $params;
  39. /**
  40. * XMLRPCClient client class constructor accepts host (required) and port (optional, default 80) arguments
  41. * @method XMLRPCClient
  42. * @param string host
  43. * @param optional int port
  44. */
  45. function XMLRPCClient($host, $port = 80) {
  46. $this->HTTPClient($host, $port);
  47. $this->setRequestMethod("POST");
  48. $this->addRequestHeaderRaw("Content-type: text/xml");
  49. $this->xml = new XML("methodCall");
  50. $this->xml->setTagContent("", "methodCall/methodName");
  51. $this->xml->setTagContent("", "methodCall/params");
  52. $this->xmlDoc = new XMLDocument();
  53. $this->xmlDoc->setXML($this->xml);
  54. $paramsBranchArray = &$this->xml->getBranches("methodCall", "params");
  55. $this->params = &$paramsBranchArray[0];
  56. // this call not necessary if we can somehow update body before HTTPClient->sendRequest
  57. $this->setRequestBody($this->xmlDoc->getXMLString());
  58. }
  59. /**
  60. * Adds a parameter to a method call in XMLRPC request
  61. * @method addParam
  62. * @param string paramType
  63. * @param mixed paramValue
  64. * @returns none
  65. */
  66. function addParam($paramType, $paramValue) {
  67. $newParam = new XMLBranch("param");
  68. $newParam->setTagContent($paramValue, "param/value/$paramType");
  69. $this->params->addXMLBranch($newParam);
  70. // this call not necessary if we can somehow update body before HTTPClient->sendRequest
  71. $this->setRequestBody($this->xmlDoc->getXMLString());
  72. }
  73. /**
  74. * Sets method name in XMLRPC request
  75. * @method setMethodName
  76. * @param string methodName
  77. * @returns none
  78. */
  79. function setMethodName ($methodName) {
  80. $this->xml->setTagContent($methodName, "methodCall/methodName");
  81. // this call not necessary if we can somehow update body before HTTPClient->sendRequest
  82. $this->setRequestBody($this->xmlDoc->getXMLString());
  83. }
  84. /**
  85. * Sets XMLRPC request by supplying an XMLDocument object
  86. * @method setRequestXML
  87. * @param object XMLDocument
  88. * @returns true if successful, false otherwise
  89. */
  90. function setRequestXML(&$XMLDocument) {
  91. if(is_object($XMLDocument) && strtolower(get_class($XMLDocument)) == "xmldocument") {
  92. $this->xmlDoc = &$XMLDocument;
  93. $this->xml = &$this->xmlDoc->getXML();
  94. $this->params = &$this->xml->getBranches("methodCall", "params");
  95. // this call not necessary if we can somehow update body before HTTPClient->sendRequest
  96. $this->setRequestBody(htmlspecialchars($this->xmlDoc->getXMLString()));
  97. $success = true;
  98. }
  99. else
  100. $success = false;
  101. return $success;
  102. }
  103. }
  104. ?>