ExampleService.php 12 KB

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