ExampleServiceflash.php 13 KB

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