ExampleServiceflash.php 12 KB

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