ExampleService_raw.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /**
  3. * This file is part of amfPHP
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the license that is bundled
  8. * with this package in the file license.txt.
  9. */
  10. /**
  11. * This is a test/example service. Remove it for production use
  12. *
  13. * @package Amfphp_Services
  14. * @author Ariel Sommeria-klein
  15. */
  16. class ExampleService {
  17. public function callmeplease($id,$name,$text1,$text2,$text3)
  18. {
  19. $dbhost = 'localhost';
  20. $dbuser = 'root';
  21. $dbpass = 'esciedu';
  22. $dbname = 'NeoSCORM2007';
  23. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  24. mysql_query("SET NAMES 'utf8'");
  25. mysql_select_db($dbname);
  26. $sql = "INSERT INTO test_for_flash VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '', '', '', '', '', '', '')";
  27. $result = mysql_query($sql) or die('MySQL query error');
  28. return $text;
  29. }
  30. /**
  31. * return one param
  32. * @param mixed $param example: {"_explicitType":"myType", "intVal":2, "stringVal":"bla", "arrayVal":[1,2, "ert"]}
  33. * @return mixed
  34. */
  35. public function returnOneParam($param) {
  36. return $param;
  37. }
  38. /**
  39. * return sum
  40. * @param int $number1 example: 2
  41. * @param int $number2 example: 3
  42. * @return int
  43. */
  44. public function returnSum($number1, $number2) {
  45. return $number1 + $number2;
  46. }
  47. /**
  48. * return null
  49. * @return null
  50. */
  51. public function returnNull() {
  52. return null;
  53. }
  54. /**
  55. * return bla
  56. * @return String
  57. */
  58. public function returnBla() {
  59. return 'bla';
  60. }
  61. /**
  62. * throy exception
  63. * @param string $arg1
  64. * @throws Exception
  65. */
  66. public function throwException($arg1) {
  67. throw new Exception("test exception $arg1", 123);
  68. }
  69. /**
  70. * return after one second
  71. * @return String
  72. */
  73. public function returnAfterOneSecond() {
  74. sleep(1);
  75. return 'slept for 1 second';
  76. }
  77. /**
  78. * return test header
  79. * @return mixed
  80. */
  81. public function returnTestHeader() {
  82. $header = Amfphp_Core_Amf_Handler::$requestPacket->headers[0];
  83. return $header->data;
  84. }
  85. /**
  86. * shouldn't appear in the service browser or be available as a service
  87. */
  88. public function _reservedMethod() {
  89. }
  90. /**
  91. * return array
  92. * @return array
  93. */
  94. public function returnArray() {
  95. return array(0, 1 => 2, 3 => 4, 5 => array(6 => 7));
  96. }
  97. /**
  98. * return opposite
  99. * @param boolean $value
  100. * @return boolean
  101. */
  102. public function returnOpposite($value) {
  103. return!$value;
  104. }
  105. /**
  106. * return bitwise and
  107. * @param boolean $value1
  108. * @param boolean $value2
  109. * @return boolean
  110. */
  111. public function returnBitwiseAnd($value1, $value2) {
  112. return ($value1 && $value2);
  113. }
  114. /**
  115. * static return one param
  116. * @param mixed $param
  117. * @return mixed
  118. */
  119. public static function staticReturnOneParam($param) {
  120. return $param;
  121. }
  122. /**
  123. * use to test for serialization performance. Each item contains a random int, float, and string
  124. * @param int $numItems example: 1000
  125. * @return array
  126. */
  127. public function returnLargeDataSet($numItems) {
  128. $ret = array();
  129. for ($i = 0; $i < $numItems; $i++) {
  130. $item = new stdClass();
  131. $item->int = rand(-1000, 1000);
  132. $item->float = rand(-1000, 1000) / 100;
  133. $item->string = md5(rand(-1000, 1000));
  134. $ret[] = $item;
  135. }
  136. return $ret;
  137. }
  138. /**
  139. * use to test Vo conversion performance. Each item contains a random int, float, and string, and is typed
  140. * @param int $numItems example: 1000
  141. * @return array
  142. */
  143. public function returnLargeTypedDataSet($numItems) {
  144. $ret = array();
  145. for ($i = 0; $i < $numItems; $i++) {
  146. $item = new DummyVo();
  147. $item->int = rand(-1000, 1000);
  148. $item->float = rand(-1000, 1000) / 100;
  149. $item->string = md5(rand(-1000, 1000));
  150. $ret[] = $item;
  151. }
  152. return $ret;
  153. }
  154. /**
  155. * dummy function to see how the backoffice tools react when there are many parameters.
  156. * @param type $a
  157. * @param type $b
  158. * @param type $c
  159. * @param type $d
  160. * @param type $e
  161. * @param type $f
  162. */
  163. public function manyParams($a, $b, $c, $d, $e, $f){
  164. }
  165. /**
  166. * simply to see if this doesn't appear in the back office, but is still callable
  167. * @amfphpHide
  168. */
  169. public function testAmfphpHide(){
  170. return "bla";
  171. }
  172. /**
  173. * receives an array(flex array collections are deserialized to arrays), and sends back an array collection.
  174. */
  175. public function testArrayCollection(array $data){
  176. $ret = new stdClass();
  177. $explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
  178. $ret->$explicitTypeField = "flex.messaging.io.ArrayCollection";
  179. $ret->source = $data;
  180. return $ret;
  181. }
  182. /**
  183. * useful for testing a messy, nested typed obj
  184. * @param mixed $param example: {"_explicitType":"UserVo1", "name":"ariel", "status":"bla", "sub1": {"_explicitType":"Sub1", "name":"ariel", "status":"bla", "sub2": {"_explicitType":"Sub2", "name":"ariel", "status":"bla"}, "sub2again": {"_explicitType":"Sub2", "name":"ariel2", "status":"bla2"}}}
  185. */
  186. public function testComplicatedTypedObj($param){
  187. return $param;
  188. }
  189. /**
  190. * adds custom markers for monitoring
  191. */
  192. public function testCustomMonitorTime(){
  193. usleep(200000);
  194. AmfphpMonitor::addTime('operation 1');
  195. usleep(200000);
  196. AmfphpMonitor::addTime('operation 2');
  197. usleep(200000);
  198. AmfphpMonitor::addTime('operation 3');
  199. return 'bla';
  200. }
  201. }
  202. /**
  203. * dummy class
  204. */
  205. class DummyVo {}
  206. ?>