ExampleService_Q.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 = '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 PS_flash_Q1 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 callmepleaseQ2($id,$name,$text1,$text2,$text3,$text4)
  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 PS_flash_Q2 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 callmepleaseQ3($id,$name,$text1,$text2,$text3)
  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 PS_flash_Q3 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 callmepleaseQ4($id,$name,$text1,$text2,$text3)
  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 PS_flash_Q4 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 callmepleaseQ5($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 PS_flash_Q5 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '', '', '', '', '', '')";
  79. $result = mysql_query($sql) or die('MySQL query error');
  80. return $text;
  81. }
  82. public function callmepleaseQ6($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 PS_flash_Q6 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '', '', '', '', '', '')";
  92. $result = mysql_query($sql) or die('MySQL query error');
  93. return $text;
  94. }
  95. public function callmepleaseQ7($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 PS_flash_Q7 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '', '', '', '', '', '')";
  105. $result = mysql_query($sql) or die('MySQL query error');
  106. return $text;
  107. }
  108. public function callmepleaseQ8($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 PS_flash_Q8 VALUES ('".$id."','".$name."', '".date('Y-m-d H:i:s')."','".$text1."', '".$text2."', '".$text3."', '".$text4."', '', '', '', '', '', '')";
  118. $result = mysql_query($sql) or die('MySQL query error');
  119. return $text;
  120. }
  121. /**
  122. * return one param
  123. * @param mixed $param example: {"_explicitType":"myType", "intVal":2, "stringVal":"bla", "arrayVal":[1,2, "ert"]}
  124. * @return mixed
  125. */
  126. public function returnOneParam($param) {
  127. return $param;
  128. }
  129. /**
  130. * return sum
  131. * @param int $number1 example: 2
  132. * @param int $number2 example: 3
  133. * @return int
  134. */
  135. public function returnSum($number1, $number2) {
  136. return $number1 + $number2;
  137. }
  138. /**
  139. * return null
  140. * @return null
  141. */
  142. public function returnNull() {
  143. return null;
  144. }
  145. /**
  146. * return bla
  147. * @return String
  148. */
  149. public function returnBla() {
  150. return 'bla';
  151. }
  152. /**
  153. * throy exception
  154. * @param string $arg1
  155. * @throws Exception
  156. */
  157. public function throwException($arg1) {
  158. throw new Exception("test exception $arg1", 123);
  159. }
  160. /**
  161. * return after one second
  162. * @return String
  163. */
  164. public function returnAfterOneSecond() {
  165. sleep(1);
  166. return 'slept for 1 second';
  167. }
  168. /**
  169. * return test header
  170. * @return mixed
  171. */
  172. public function returnTestHeader() {
  173. $header = Amfphp_Core_Amf_Handler::$requestPacket->headers[0];
  174. return $header->data;
  175. }
  176. /**
  177. * shouldn't appear in the service browser or be available as a service
  178. */
  179. public function _reservedMethod() {
  180. }
  181. /**
  182. * return array
  183. * @return array
  184. */
  185. public function returnArray() {
  186. return array(0, 1 => 2, 3 => 4, 5 => array(6 => 7));
  187. }
  188. /**
  189. * return opposite
  190. * @param boolean $value
  191. * @return boolean
  192. */
  193. public function returnOpposite($value) {
  194. return!$value;
  195. }
  196. /**
  197. * return bitwise and
  198. * @param boolean $value1
  199. * @param boolean $value2
  200. * @return boolean
  201. */
  202. public function returnBitwiseAnd($value1, $value2) {
  203. return ($value1 && $value2);
  204. }
  205. /**
  206. * static return one param
  207. * @param mixed $param
  208. * @return mixed
  209. */
  210. public static function staticReturnOneParam($param) {
  211. return $param;
  212. }
  213. /**
  214. * use to test for serialization performance. Each item contains a random int, float, and string
  215. * @param int $numItems example: 1000
  216. * @return array
  217. */
  218. public function returnLargeDataSet($numItems) {
  219. $ret = array();
  220. for ($i = 0; $i < $numItems; $i++) {
  221. $item = new stdClass();
  222. $item->int = rand(-1000, 1000);
  223. $item->float = rand(-1000, 1000) / 100;
  224. $item->string = md5(rand(-1000, 1000));
  225. $ret[] = $item;
  226. }
  227. return $ret;
  228. }
  229. /**
  230. * use to test Vo conversion performance. Each item contains a random int, float, and string, and is typed
  231. * @param int $numItems example: 1000
  232. * @return array
  233. */
  234. public function returnLargeTypedDataSet($numItems) {
  235. $ret = array();
  236. for ($i = 0; $i < $numItems; $i++) {
  237. $item = new DummyVo();
  238. $item->int = rand(-1000, 1000);
  239. $item->float = rand(-1000, 1000) / 100;
  240. $item->string = md5(rand(-1000, 1000));
  241. $ret[] = $item;
  242. }
  243. return $ret;
  244. }
  245. /**
  246. * dummy function to see how the backoffice tools react when there are many parameters.
  247. * @param type $a
  248. * @param type $b
  249. * @param type $c
  250. * @param type $d
  251. * @param type $e
  252. * @param type $f
  253. */
  254. public function manyParams($a, $b, $c, $d, $e, $f){
  255. }
  256. /**
  257. * simply to see if this doesn't appear in the back office, but is still callable
  258. * @amfphpHide
  259. */
  260. public function testAmfphpHide(){
  261. return "bla";
  262. }
  263. /**
  264. * receives an array(flex array collections are deserialized to arrays), and sends back an array collection.
  265. */
  266. public function testArrayCollection(array $data){
  267. $ret = new stdClass();
  268. $explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
  269. $ret->$explicitTypeField = "flex.messaging.io.ArrayCollection";
  270. $ret->source = $data;
  271. return $ret;
  272. }
  273. /**
  274. * useful for testing a messy, nested typed obj
  275. * @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"}}}
  276. */
  277. public function testComplicatedTypedObj($param){
  278. return $param;
  279. }
  280. /**
  281. * adds custom markers for monitoring
  282. */
  283. public function testCustomMonitorTime(){
  284. usleep(200000);
  285. AmfphpMonitor::addTime('operation 1');
  286. usleep(200000);
  287. AmfphpMonitor::addTime('operation 2');
  288. usleep(200000);
  289. AmfphpMonitor::addTime('operation 3');
  290. return 'bla';
  291. }
  292. }
  293. /**
  294. * dummy class
  295. */
  296. class DummyVo {}
  297. ?>