Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Wrote parseXmlRpcMethodCall()

  • Loading branch information...
commit 93e1b4c49356ed19afc4af2b4f924cd0b247b992 1 parent bfa6959
Barnaby Walters authored
Showing with 35 additions and 1 deletion.
  1. +35 −1 BarnabyWalters/Helpers/Helpers.php
36 BarnabyWalters/Helpers/Helpers.php
View
@@ -501,7 +501,41 @@ public static function findUrls($text, $tidy = true) {
public static function stringToHexColour($word) {
return substr(bin2hex(metaphone($word, 6)), 0, 6);
}
-
+
+ /**
+ * Parse XML-RPC Method Call
+ *
+ * Given an XML-RPC request body, returns an array like this:
+ *
+ * [
+ * 'methodName': 'example.ex',
+ * 'params': ['string1', 'string2]
+ * ]
+ *
+ * NOTE: Only currently accepts string parameters.
+ *
+ * @todo Make this handle param types other than `string`
+ * @param string $request
+ */
+ public static function parseXmlRpcMethodCall($request) {
+ $req = new DOMDocument('1.0');
+ $req->loadXML($request);
+
+ $q = new DOMXPath($req);
+ $methodName = $q->query('/methodCall/methodName')->item(0)->nodeValue;
+
+ $params = $q->query('/methodCall/params/param/value/string');
+ $paramArray = [];
+
+ foreach ($params as $node) {
+ $paramArray[] = $node->nodeValue;
+ }
+
+ return [
+ 'methodName' => $methodName,
+ 'params' => $paramArray
+ ];
+ }
}
// EOF Helpers.php
Please sign in to comment.
Something went wrong with that request. Please try again.