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