PageRenderTime 74ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/amfphp/core/amf/app/Actions.php

https://gitlab.com/endomorphosis/suschu
PHP | 240 lines | 165 code | 24 blank | 51 comment | 38 complexity | 8555223616236875344dc87d03d6ec47 MD5 | raw file
  1. <?php
  2. /**
  3. * Actions modify the AMF message PER BODY
  4. * This allows batching of calls
  5. *
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @copyright (c) 2003 amfphp.org
  8. * @package flashservices
  9. * @subpackage filters
  10. * @version $Id: Filters.php,v 1.6 2005/04/02 18:37:51 pmineault Exp $
  11. */
  12. /**
  13. * Catches any special request types and classifies as required
  14. */
  15. function adapterAction (&$amfbody) {
  16. $baseClassPath = $GLOBALS['amfphp']['classPath'];
  17. $uriclasspath = "";
  18. $classname = "";
  19. $classpath = "";
  20. $methodname = "";
  21. $isWebServiceURI = false;
  22. $target = $amfbody->targetURI;
  23. if (strpos($target, "http://") === false && strpos($target, "https://") === false) { // check for a http link which means web service
  24. $lpos = strrpos($target, ".");
  25. if ($lpos === false) {
  26. //Check to see if this is in fact a RemotingMessage
  27. $body = $amfbody->getValue();
  28. $handled = false;
  29. $messageType = $body[0]->_explicitType;
  30. if($messageType == 'flex.messaging.messages.RemotingMessage')
  31. {
  32. $handled = true;
  33. //Fix for AMF0 mixed array bug in Flex 2
  34. if(isset($body[0]->body['length']))
  35. {
  36. unset($body[0]->body['length']);
  37. }
  38. $amfbody->setValue($body[0]->body);
  39. $amfbody->setSpecialHandling("RemotingMessage");
  40. $amfbody->setMetadata("clientId", $body[0]->clientId);
  41. $amfbody->setMetadata("messageId", $body[0]->messageId);
  42. $GLOBALS['amfphp']['lastMessageId'] = $body[0]->messageId;
  43. $methodname = $body[0]->operation;
  44. $classAndPackage = $body[0]->source;
  45. $lpos = strrpos($classAndPackage, ".");
  46. if($lpos !== FALSE)
  47. {
  48. $classname = substr($classAndPackage, $lpos + 1);
  49. }
  50. else
  51. {
  52. $classname = $classAndPackage;
  53. }
  54. $uriclasspath = str_replace('.','/',$classAndPackage) . '.php';
  55. $classpath = $baseClassPath . $uriclasspath;
  56. }
  57. elseif($messageType == "flex.messaging.messages.CommandMessage")
  58. {
  59. if($body[0]->operation == 5)
  60. {
  61. $handled = true;
  62. $amfbody->setSpecialHandling("Ping");
  63. $amfbody->setMetadata("clientId", $body[0]->clientId);
  64. $amfbody->setMetadata("messageId", $body[0]->messageId);
  65. $amfbody->noExec = true;
  66. }
  67. }
  68. if(!$handled)
  69. {
  70. $uriclasspath = "amfphp/Amf3Broker.php";
  71. $classpath = $baseClassPath . "amfphp/Amf3Broker.php";
  72. $classname = "Amf3Broker";
  73. $methodname = "handleMessage";
  74. }
  75. } else {
  76. $methodname = substr($target, $lpos + 1);
  77. $trunced = substr($target, 0, $lpos);
  78. $lpos = strrpos($trunced, ".");
  79. if ($lpos === false) {
  80. $classname = $trunced;
  81. if ($classname == "PageAbleResult" && $methodname == 'getRecords') {
  82. $val = $amfbody->getValue();
  83. $id = $val[0];
  84. $keys = explode("=", $id);
  85. $currset = intval($keys[1]);
  86. $set = $_SESSION['amfphp_recordsets'][$currset];
  87. $uriclasspath = $set['class'];
  88. $classpath = $baseClassPath . $set['class'];
  89. $methodname = $set['method'];
  90. $classname = substr(strrchr('/' . $set['class'], '/'), 1, -4);
  91. //Now set args for body
  92. $amfbody->setValue(array_merge($set['args'], array($val[1], $val[2])));
  93. //Tell amfbody that this is a dynamic paged resultset
  94. $amfbody->setSpecialHandling('pageFetch');
  95. }
  96. else if($classname == "PageAbleResult" && $methodname == 'release')
  97. {
  98. $amfbody->setSpecialHandling('pageRelease');
  99. $amfbody->noExec = true;
  100. }
  101. else {
  102. $uriclasspath = $trunced . ".php";
  103. $classpath = $baseClassPath . $trunced . ".php";
  104. }
  105. } else {
  106. $classname = substr($trunced, $lpos + 1);
  107. $classpath = $baseClassPath . str_replace(".", "/", $trunced) . ".php"; // removed to strip the basecp out of the equation here
  108. $uriclasspath = str_replace(".", "/", $trunced) . ".php"; // removed to strip the basecp out of the equation here
  109. }
  110. }
  111. } else { // This is a web service and is unsupported
  112. trigger_error("Web services are not supported in this release", E_USER_ERROR);
  113. }
  114. $amfbody->classPath = $classpath;
  115. $amfbody->uriClassPath = $uriclasspath;
  116. $amfbody->className = $classname;
  117. $amfbody->methodName = $methodname;
  118. return true;
  119. }
  120. /**
  121. * ExecutionAction executes the required methods
  122. */
  123. function executionAction (&$amfbody)
  124. {
  125. $specialHandling = $amfbody->getSpecialHandling();
  126. if (!$amfbody->isSpecialHandling() || $amfbody->isSpecialHandling(array('describeService', 'pageFetch', 'RemotingMessage')))
  127. {
  128. $construct = &$amfbody->getClassConstruct();
  129. $method = $amfbody->methodName;
  130. $args = $amfbody->getValue();
  131. if($specialHandling == 'describeService')
  132. {
  133. include_once(AMFPHP_BASE . "util/DescribeService.php");
  134. $ds = new DescribeService();
  135. $results = $ds->describe($construct, $amfbody->className);
  136. }
  137. else if($specialHandling == 'pageFetch')
  138. {
  139. $args[count($args) - 2] = $args[count($args) - 2] - 1;
  140. $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args);
  141. $results = array("cursor" => $args[count($args) - 2] + 1,
  142. "data" => $dataset);
  143. $amfbody->setMetadata('type', '__DYNAMIC_PAGE__');
  144. }
  145. else
  146. {
  147. /*
  148. if(isset($construct->methodTable[$method]['pagesize']))
  149. {
  150. //Check if counting method was overriden
  151. if(isset($construct->methodTable[$method]['countMethod']))
  152. {
  153. $counter = $construct->methodTable[$method]['countMethod'];
  154. }
  155. else
  156. {
  157. $counter = $method . '_count';
  158. }
  159. $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args); // do the magic
  160. $count = Executive::doMethodCall($amfbody, $construct, $counter, $args);
  161. //Include the wrapper
  162. $results = array('class' => $amfbody->uriClassPath,
  163. 'method' => $amfbody->methodName,
  164. 'count' => $count,
  165. "args" => $args,
  166. "data" => $dataset);
  167. $amfbody->setMetadata('type', '__DYNAMIC_PAGEABLE_RESULTSET__');
  168. $amfbody->setMetadata('pagesize', $construct->methodTable[$method]['pagesize']);
  169. */
  170. //}
  171. //else
  172. //{
  173. //The usual
  174. $time = microtime_float();
  175. $results = Executive::doMethodCall($amfbody, $construct, $method, $args); // do the magic
  176. global $amfphp;
  177. $amfphp['callTime'] += microtime_float() - $time;
  178. //}
  179. }
  180. if($results !== '__amfphp_error')
  181. {
  182. if($specialHandling == 'RemotingMessage')
  183. {
  184. $wrapper = new AcknowledgeMessage($amfbody->getMetadata("messageId"),
  185. $amfbody->getMetadata("clientId"));
  186. $wrapper->body = $results;
  187. $amfbody->setResults($wrapper);
  188. }
  189. else
  190. {
  191. $amfbody->setResults($results);
  192. }
  193. $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
  194. }
  195. return false;
  196. }
  197. elseif($specialHandling == 'Ping')
  198. {
  199. $wrapper = new AcknowledgeMessage($amfbody->getMetadata("messageId"),
  200. $amfbody->getMetadata("clientId"));
  201. $amfbody->setResults($wrapper);
  202. $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
  203. }
  204. else if($specialHandling == 'pageRelease')
  205. {
  206. //Ignore PageAbleResult.release
  207. $amfbody->setResults(true);
  208. $amfbody->setMetaData('type', 'boolean');
  209. $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
  210. return false;
  211. }
  212. return true;
  213. }
  214. ?>