ExampleService.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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_flash1_1($id,$name,$text1,$text2,$text3,$text4)
  18. {
  19. $dbhost = 'localhost';
  20. $dbuser = 'wenchi';
  21. $dbpass = 'wenchi';
  22. $dbname = 'wenchi';
  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 flash1_1 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '', '', '', '', '', '')";
  27. $result = mysql_query($sql) or die('MySQL query error');
  28. return $text;
  29. }
  30. public function callmeplease_flash1_2($id,$name,$text1,$text2,$text3,$text4)
  31. {
  32. $dbhost = 'localhost';
  33. $dbuser = 'wenchi';
  34. $dbpass = 'wenchi';
  35. $dbname = 'wenchi';
  36. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  37. mysql_query("SET NAMES 'utf8'");
  38. mysql_select_db($dbname);
  39. $sql = "INSERT INTO flash1_2 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '', '', '', '', '', '')";
  40. $result = mysql_query($sql) or die('MySQL query error');
  41. return $text;
  42. }
  43. public function callmeplease_flash2_1($id,$name,$text1,$text2,$text3,$text4)
  44. {
  45. $dbhost = 'localhost';
  46. $dbuser = 'wenchi';
  47. $dbpass = 'wenchi';
  48. $dbname = 'wenchi';
  49. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  50. mysql_query("SET NAMES 'utf8'");
  51. mysql_select_db($dbname);
  52. $sql = "INSERT INTO flash2_1 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '', '', '', '', '', '', '')";
  53. $result = mysql_query($sql) or die('MySQL query error');
  54. return $text;
  55. }
  56. public function callmeplease_flash2_2($id,$name,$text1,$text2,$text3,$text4)
  57. {
  58. $dbhost = 'localhost';
  59. $dbuser = 'wenchi';
  60. $dbpass = 'wenchi';
  61. $dbname = 'wenchi';
  62. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  63. mysql_query("SET NAMES 'utf8'");
  64. mysql_select_db($dbname);
  65. $sql = "INSERT INTO flash2_2 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '', '', '', '', '', '', '')";
  66. $result = mysql_query($sql) or die('MySQL query error');
  67. return $text;
  68. }
  69. public function callmeplease_flash3_1($id,$name,$text1,$text2,$text3,$text4)
  70. {
  71. $dbhost = 'localhost';
  72. $dbuser = 'wenchi';
  73. $dbpass = 'wenchi';
  74. $dbname = 'wenchi';
  75. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  76. mysql_query("SET NAMES 'utf8'");
  77. mysql_select_db($dbname);
  78. $sql = "INSERT INTO flash3_1 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '', '', '', '', '', '', '')";
  79. $result = mysql_query($sql) or die('MySQL query error');
  80. return $text;
  81. }
  82. public function callmeplease_flash3_2($id,$name,$text1,$text2,$text3,$text4)
  83. {
  84. $dbhost = 'localhost';
  85. $dbuser = 'wenchi';
  86. $dbpass = 'wenchi';
  87. $dbname = 'wenchi';
  88. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  89. mysql_query("SET NAMES 'utf8'");
  90. mysql_select_db($dbname);
  91. $sql = "INSERT INTO flash3_2 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '', '', '', '', '', '', '')";
  92. $result = mysql_query($sql) or die('MySQL query error');
  93. return $text;
  94. }
  95. public function callmeplease_flash4($id,$name,$text1,$text2,$text3,$text4)
  96. {
  97. $dbhost = 'localhost';
  98. $dbuser = 'wenchi';
  99. $dbpass = 'wenchi';
  100. $dbname = 'wenchi';
  101. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  102. mysql_query("SET NAMES 'utf8'");
  103. mysql_select_db($dbname);
  104. $sql = "INSERT INTO flash4 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '', '', '', '', '', '', '')";
  105. $result = mysql_query($sql) or die('MySQL query error');
  106. return $text;
  107. }
  108. public function callmeplease_flash5_1($id,$name,$text1,$text2,$text3,$text4,$text5,$text6,$text7)
  109. {
  110. $dbhost = 'localhost';
  111. $dbuser = 'wenchi';
  112. $dbpass = 'wenchi';
  113. $dbname = 'wenchi';
  114. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  115. mysql_query("SET NAMES 'utf8'");
  116. mysql_select_db($dbname);
  117. $sql = "INSERT INTO flash5_1 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '".$text5."', '".$text6."', '".$text7."', '', '', '')";
  118. $result = mysql_query($sql) or die('MySQL query error');
  119. return $text;
  120. }
  121. public function callmeplease_flash5_2($id,$name,$text1,$text2,$text3,$text4,$text5,$text6,$text7)
  122. {
  123. $dbhost = 'localhost';
  124. $dbuser = 'wenchi';
  125. $dbpass = 'wenchi';
  126. $dbname = 'wenchi';
  127. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  128. mysql_query("SET NAMES 'utf8'");
  129. mysql_select_db($dbname);
  130. $sql = "INSERT INTO flash5_2 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '".$text5."', '".$text6."', '".$text7."', '', '', '')";
  131. $result = mysql_query($sql) or die('MySQL query error');
  132. return $text;
  133. }
  134. /**
  135. * return one param
  136. * @param mixed $param example: {"_explicitType":"myType", "intVal":2, "stringVal":"bla", "arrayVal":[1,2, "ert"]}
  137. * @return mixed
  138. */
  139. public function returnOneParam($param) {
  140. return $param;
  141. }
  142. /**
  143. * return sum
  144. * @param int $number1 example: 2
  145. * @param int $number2 example: 3
  146. * @return int
  147. */
  148. public function returnSum($number1, $number2) {
  149. return $number1 + $number2;
  150. }
  151. /**
  152. * return null
  153. * @return null
  154. */
  155. public function returnNull() {
  156. return null;
  157. }
  158. /**
  159. * return bla
  160. * @return String
  161. */
  162. public function returnBla() {
  163. return 'bla';
  164. }
  165. /**
  166. * throy exception
  167. * @param string $arg1
  168. * @throws Exception
  169. */
  170. public function throwException($arg1) {
  171. throw new Exception("test exception $arg1", 123);
  172. }
  173. /**
  174. * return after one second
  175. * @return String
  176. */
  177. public function returnAfterOneSecond() {
  178. sleep(1);
  179. return 'slept for 1 second';
  180. }
  181. /**
  182. * return test header
  183. * @return mixed
  184. */
  185. public function returnTestHeader() {
  186. $header = Amfphp_Core_Amf_Handler::$requestPacket->headers[0];
  187. return $header->data;
  188. }
  189. /**
  190. * shouldn't appear in the service browser or be available as a service
  191. */
  192. public function _reservedMethod() {
  193. }
  194. /**
  195. * return array
  196. * @return array
  197. */
  198. public function returnArray() {
  199. return array(0, 1 => 2, 3 => 4, 5 => array(6 => 7));
  200. }
  201. /**
  202. * return opposite
  203. * @param boolean $value
  204. * @return boolean
  205. */
  206. public function returnOpposite($value) {
  207. return!$value;
  208. }
  209. /**
  210. * return bitwise and
  211. * @param boolean $value1
  212. * @param boolean $value2
  213. * @return boolean
  214. */
  215. public function returnBitwiseAnd($value1, $value2) {
  216. return ($value1 && $value2);
  217. }
  218. /**
  219. * static return one param
  220. * @param mixed $param
  221. * @return mixed
  222. */
  223. public static function staticReturnOneParam($param) {
  224. return $param;
  225. }
  226. /**
  227. * use to test for serialization performance. Each item contains a random int, float, and string
  228. * @param int $numItems example: 1000
  229. * @return array
  230. */
  231. public function returnLargeDataSet($numItems) {
  232. $ret = array();
  233. for ($i = 0; $i < $numItems; $i++) {
  234. $item = new stdClass();
  235. $item->int = rand(-1000, 1000);
  236. $item->float = rand(-1000, 1000) / 100;
  237. $item->string = md5(rand(-1000, 1000));
  238. $ret[] = $item;
  239. }
  240. return $ret;
  241. }
  242. /**
  243. * use to test Vo conversion performance. Each item contains a random int, float, and string, and is typed
  244. * @param int $numItems example: 1000
  245. * @return array
  246. */
  247. public function returnLargeTypedDataSet($numItems) {
  248. $ret = array();
  249. for ($i = 0; $i < $numItems; $i++) {
  250. $item = new DummyVo();
  251. $item->int = rand(-1000, 1000);
  252. $item->float = rand(-1000, 1000) / 100;
  253. $item->string = md5(rand(-1000, 1000));
  254. $ret[] = $item;
  255. }
  256. return $ret;
  257. }
  258. /**
  259. * dummy function to see how the backoffice tools react when there are many parameters.
  260. * @param type $a
  261. * @param type $b
  262. * @param type $c
  263. * @param type $d
  264. * @param type $e
  265. * @param type $f
  266. */
  267. public function manyParams($a, $b, $c, $d, $e, $f){
  268. }
  269. /**
  270. * simply to see if this doesn't appear in the back office, but is still callable
  271. * @amfphpHide
  272. */
  273. public function testAmfphpHide(){
  274. return "bla";
  275. }
  276. /**
  277. * receives an array(flex array collections are deserialized to arrays), and sends back an array collection.
  278. */
  279. public function testArrayCollection(array $data){
  280. $ret = new stdClass();
  281. $explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
  282. $ret->$explicitTypeField = "flex.messaging.io.ArrayCollection";
  283. $ret->source = $data;
  284. return $ret;
  285. }
  286. /**
  287. * useful for testing a messy, nested typed obj
  288. * @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"}}}
  289. */
  290. public function testComplicatedTypedObj($param){
  291. return $param;
  292. }
  293. /**
  294. * adds custom markers for monitoring
  295. */
  296. public function testCustomMonitorTime(){
  297. usleep(200000);
  298. AmfphpMonitor::addTime('operation 1');
  299. usleep(200000);
  300. AmfphpMonitor::addTime('operation 2');
  301. usleep(200000);
  302. AmfphpMonitor::addTime('operation 3');
  303. return 'bla';
  304. }
  305. }
  306. /**
  307. * dummy class
  308. */
  309. class DummyVo {}
  310. ?>