Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added XmlRpcFaultResponse, docblocks and use statements

  • Loading branch information...
commit a83f5d238a11a8b82249129e7c39adf0d1581359 1 parent d2cf84c
Barnaby Walters authored
Showing with 47 additions and 0 deletions.
  1. +47 −0 BarnabyWalters/Helpers/Helpers.php
47 BarnabyWalters/Helpers/Helpers.php
View
@@ -4,6 +4,9 @@
use Carbon\Carbon;
use DateTime;
+use DOMDocument;
+use DOMElement;
+use DOMXPath;
/**
* Functional Helpers
@@ -516,6 +519,7 @@ public static function stringToHexColour($word) {
*
* @todo Make this handle param types other than `string`
* @param string $request
+ * @return array
*/
public static function parseXmlRpcMethodCall($request) {
$req = new DOMDocument('1.0');
@@ -537,6 +541,16 @@ public static function parseXmlRpcMethodCall($request) {
];
}
+ /**
+ * Create XML-RPC Success Response
+ *
+ * Given the value to return (can only be a string at the mo), creates a
+ * response.
+ *
+ * @param string $retVal The string to return
+ * @param bool $asString Whether or not to return the respons as a string or DOMDocument
+ * @return DOMDocument
+ */
public static function createXmlRpcSuccessResponse($retVal, $asString = true) {
$doc = new DOMDocument('1.0');
$methodResponse = new DOMElement('methodResponse');
@@ -556,6 +570,39 @@ public static function createXmlRpcSuccessResponse($retVal, $asString = true) {
else
return $doc->saveXML();
}
+
+ /**
+ * Create XML-RPC Fault Response
+ *
+ * Creates an XML-RPC Fault response with either an int or a string as the
+ * fault.
+ *
+ * @param string|int $fault
+ * @param bool $asString
+ * @return \DOMDocument
+ */
+ public static function createXmlRpcFaultResponse($fault, $asString = true) {
+ if (is_string($fault))
+ $type = 'string';
+ elseif (is_int($fault))
+ $type = 'int';
+
+ $doc = new DOMDocument('1.0');
+ $methodResponse = new DOMElement('methodResponse');
+ $response->appendChild($methodResponse);
+
+ $int = $response->createElement($type, $fault);
+ $value = $response->createElement('value');
+ $value->appendChild($int);
+ $fault = $response->createElement('fault');
+ $fault->appendChild($value);
+ $methodResponse->appendChild($fault);
+
+ if (!$asString)
+ return $doc;
+ else
+ return $doc->saveXML();
+ }
}
// EOF Helpers.php
Please sign in to comment.
Something went wrong with that request. Please try again.