summaryrefslogtreecommitdiff
path: root/demos/soap/protected/webservices
diff options
context:
space:
mode:
authorknut <>2006-07-06 19:45:32 +0000
committerknut <>2006-07-06 19:45:32 +0000
commit97dddf3cf23f7d2829d23efb9d44b746ac7d52cc (patch)
tree23c5984380a250bbe0d1163c055df2404df19649 /demos/soap/protected/webservices
parent9cc6b7fffd31f4b9ee9aceef9224c84dcf28aeb8 (diff)
Added a TSoapService prototype with a simple demo app
Diffstat (limited to 'demos/soap/protected/webservices')
-rw-r--r--demos/soap/protected/webservices/SimpleService.php89
1 files changed, 89 insertions, 0 deletions
diff --git a/demos/soap/protected/webservices/SimpleService.php b/demos/soap/protected/webservices/SimpleService.php
new file mode 100644
index 00000000..e59546bb
--- /dev/null
+++ b/demos/soap/protected/webservices/SimpleService.php
@@ -0,0 +1,89 @@
+<?php
+class SimpleService
+{
+ private $errors = array();
+
+ /**
+ * Highlights a string as php code
+ * @param string $input The php code to highlight
+ * @return string The highlighted text.
+ * @soapmethod
+ */
+ public function highlight($input)
+ {
+ return highlight_string($input, true);
+ }
+
+ /**
+ * Given a left side, operation, and right side of an operation, will
+ * return the result of computing the equation.
+ * @param string $leftSide The left side of an equation
+ * @param string $operation The operation to perform
+ * @param string $rightSide The right side of the equation
+ * @return ComputationResult The result of the computation
+ * @soapmethod
+ */
+ public function compute($leftSide, $operation, $rightSide)
+ {
+ $result = new ComputationResult();
+ $result->equation = "$leftSide $operation $rightSide";
+ $result->result = $this->evaluateExpression($leftSide, $operation, $rightSide);
+ if (count($this->errors)) {
+ $result->success = false;
+ $result->errors = $this->errors;
+ }
+ else {
+ $result->success = true;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Simply add two operands
+ * @param int $a
+ * @param int $b
+ * @return int The result
+ * @soapmethod
+ */
+ public function add($a, $b) {
+ return $a + $b;
+ }
+
+ /**
+ * This method evaluates the expression. It should be capable of handling any $op
+ * passed to it.
+ * @return string the result of the evaluation
+ */
+ private function evaluateExpression($left, $op, $right)
+ {
+ // Now, because we don't want to eval random code on the server that this is running
+ // on, we're just going to highlight the string
+ $evaluation = highlight_string("$left $op $right;", true);
+ return $evaluation;
+ }
+}
+
+class ComputationResult
+{
+ /**
+ * @var string The initial equation
+ */
+ public $equation;
+
+ /**
+ * @var string The computed result
+ */
+ public $result;
+
+ /**
+ * @var boolean Whether the computation succeeded
+ */
+ public $success;
+
+ /**
+ * @var array any errors that occured in the processing.
+ */
+ public $errors;
+}
+?> \ No newline at end of file