ExampleService_raw.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 = 'qwe110110';
  22. //$dbpass = 'esciedu';
  23. $dbname = 'NeoSCORM2007';
  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 test_for_flash 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. /**
  32. * return one param
  33. * @param mixed $param example: {"_explicitType":"myType", "intVal":2, "stringVal":"bla", "arrayVal":[1,2, "ert"]}
  34. * @return mixed
  35. */
  36. public function returnOneParam($param) {
  37. return $param;
  38. }
  39. /**
  40. * return sum
  41. * @param int $number1 example: 2
  42. * @param int $number2 example: 3
  43. * @return int
  44. */
  45. public function returnSum($number1, $number2) {
  46. return $number1 + $number2;
  47. }
  48. /**
  49. * return null
  50. * @return null
  51. */
  52. public function returnNull() {
  53. return null;
  54. }
  55. /**
  56. * return bla
  57. * @return String
  58. */
  59. public function returnBla() {
  60. return 'bla';
  61. }
  62. /**
  63. * throy exception
  64. * @param string $arg1
  65. * @throws Exception
  66. */
  67. public function throwException($arg1) {
  68. throw new Exception("test exception $arg1", 123);
  69. }
  70. /**
  71. * return after one second
  72. * @return String
  73. */
  74. public function returnAfterOneSecond() {
  75. sleep(1);
  76. return 'slept for 1 second';
  77. }
  78. /**
  79. * return test header
  80. * @return mixed
  81. */
  82. public function returnTestHeader() {
  83. $header = Amfphp_Core_Amf_Handler::$requestPacket->headers[0];
  84. return $header->data;
  85. }
  86. /**
  87. * shouldn't appear in the service browser or be available as a service
  88. */
  89. public function _reservedMethod() {
  90. }
  91. /**
  92. * return array
  93. * @return array
  94. */
  95. public function returnArray() {
  96. return array(0, 1 => 2, 3 => 4, 5 => array(6 => 7));
  97. }
  98. /**
  99. * return opposite
  100. * @param boolean $value
  101. * @return boolean
  102. */
  103. public function returnOpposite($value) {
  104. return!$value;
  105. }
  106. /**
  107. * return bitwise and
  108. * @param boolean $value1
  109. * @param boolean $value2
  110. * @return boolean
  111. */
  112. public function returnBitwiseAnd($value1, $value2) {
  113. return ($value1 && $value2);
  114. }
  115. /**
  116. * static return one param
  117. * @param mixed $param
  118. * @return mixed
  119. */
  120. public static function staticReturnOneParam($param) {
  121. return $param;
  122. }
  123. /**
  124. * use to test for serialization performance. Each item contains a random int, float, and string
  125. * @param int $numItems example: 1000
  126. * @return array
  127. */
  128. public function returnLargeDataSet($numItems) {
  129. $ret = array();
  130. for ($i = 0; $i < $numItems; $i++) {
  131. $item = new stdClass();
  132. $item->int = rand(-1000, 1000);
  133. $item->float = rand(-1000, 1000) / 100;
  134. $item->string = md5(rand(-1000, 1000));
  135. $ret[] = $item;
  136. }
  137. return $ret;
  138. }
  139. /**
  140. * use to test Vo conversion performance. Each item contains a random int, float, and string, and is typed
  141. * @param int $numItems example: 1000
  142. * @return array
  143. */
  144. public function returnLargeTypedDataSet($numItems) {
  145. $ret = array();
  146. for ($i = 0; $i < $numItems; $i++) {
  147. $item = new DummyVo();
  148. $item->int = rand(-1000, 1000);
  149. $item->float = rand(-1000, 1000) / 100;
  150. $item->string = md5(rand(-1000, 1000));
  151. $ret[] = $item;
  152. }
  153. return $ret;
  154. }
  155. /**
  156. * dummy function to see how the backoffice tools react when there are many parameters.
  157. * @param type $a
  158. * @param type $b
  159. * @param type $c
  160. * @param type $d
  161. * @param type $e
  162. * @param type $f
  163. */
  164. public function manyParams($a, $b, $c, $d, $e, $f){
  165. }
  166. /**
  167. * simply to see if this doesn't appear in the back office, but is still callable
  168. * @amfphpHide
  169. */
  170. public function testAmfphpHide(){
  171. return "bla";
  172. }
  173. /**
  174. * receives an array(flex array collections are deserialized to arrays), and sends back an array collection.
  175. */
  176. public function testArrayCollection(array $data){
  177. $ret = new stdClass();
  178. $explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
  179. $ret->$explicitTypeField = "flex.messaging.io.ArrayCollection";
  180. $ret->source = $data;
  181. return $ret;
  182. }
  183. /**
  184. * useful for testing a messy, nested typed obj
  185. * @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"}}}
  186. */
  187. public function testComplicatedTypedObj($param){
  188. return $param;
  189. }
  190. /**
  191. * adds custom markers for monitoring
  192. */
  193. public function testCustomMonitorTime(){
  194. usleep(200000);
  195. AmfphpMonitor::addTime('operation 1');
  196. usleep(200000);
  197. AmfphpMonitor::addTime('operation 2');
  198. usleep(200000);
  199. AmfphpMonitor::addTime('operation 3');
  200. return 'bla';
  201. }
  202. }
  203. /**
  204. * dummy class
  205. */
  206. class DummyVo {}
  207. ?>