ExampleService_Q.php 11 KB

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