PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://aerial-cms.googlecode.com/
PHP | 250 lines | 168 code | 27 blank | 55 comment | 40 complexity | 4ff070e2fcc6a63b5031dd25cdda06a2 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. if(realpath(INTERNAL_SERVICES_PATH."/".$uriclasspath))
  56. $classpath = realpath(INTERNAL_SERVICES_PATH."/".$uriclasspath);
  57. if(realpath(BACKEND_SERVICES_PATH."/".$uriclasspath))
  58. $classpath = realpath(BACKEND_SERVICES_PATH."/".$uriclasspath);
  59. //$classpath = $baseClassPath . $uriclasspath;
  60. //die($classpath);
  61. }
  62. elseif($messageType == "flex.messaging.messages.CommandMessage")
  63. {
  64. if($body[0]->operation == 5)
  65. {
  66. $handled = true;
  67. $amfbody->setSpecialHandling("Ping");
  68. $amfbody->setMetadata("clientId", $body[0]->clientId);
  69. $amfbody->setMetadata("messageId", $body[0]->messageId);
  70. $amfbody->noExec = true;
  71. }
  72. }
  73. if(!$handled)
  74. {
  75. //print_r($amfbody);
  76. //die();
  77. $uriclasspath = "amfphp/Amf3Broker.php";
  78. $classpath = $baseClassPath . "amfphp/Amf3Broker.php";
  79. $classname = "Amf3Broker";
  80. $methodname = "handleMessage";
  81. }
  82. } else {
  83. $methodname = substr($target, $lpos + 1);
  84. $trunced = substr($target, 0, $lpos);
  85. $lpos = strrpos($trunced, ".");
  86. if ($lpos === false) {
  87. $classname = $trunced;
  88. if ($classname == "PageAbleResult" && $methodname == 'getRecords') {
  89. $val = $amfbody->getValue();
  90. $id = $val[0];
  91. $keys = explode("=", $id);
  92. $currset = intval($keys[1]);
  93. $set = $_SESSION['amfphp_recordsets'][$currset];
  94. $uriclasspath = $set['class'];
  95. $classpath = $baseClassPath . $set['class'];
  96. $methodname = $set['method'];
  97. $classname = substr(strrchr('/' . $set['class'], '/'), 1, -4);
  98. //Now set args for body
  99. $amfbody->setValue(array_merge($set['args'], array($val[1], $val[2])));
  100. //Tell amfbody that this is a dynamic paged resultset
  101. $amfbody->setSpecialHandling('pageFetch');
  102. }
  103. else if($classname == "PageAbleResult" && $methodname == 'release')
  104. {
  105. $amfbody->setSpecialHandling('pageRelease');
  106. $amfbody->noExec = true;
  107. }
  108. else {
  109. $uriclasspath = $trunced . ".php";
  110. $classpath = $baseClassPath . $trunced . ".php";
  111. }
  112. } else {
  113. $classname = substr($trunced, $lpos + 1);
  114. $classpath = $baseClassPath . str_replace(".", "/", $trunced) . ".php"; // removed to strip the basecp out of the equation here
  115. $uriclasspath = str_replace(".", "/", $trunced) . ".php"; // removed to strip the basecp out of the equation here
  116. }
  117. }
  118. } else { // This is a web service and is unsupported
  119. trigger_error("Web services are not supported in this release", E_USER_ERROR);
  120. }
  121. $amfbody->classPath = $classpath;
  122. $amfbody->uriClassPath = $uriclasspath;
  123. $amfbody->className = $classname;
  124. $amfbody->methodName = $methodname;
  125. return true;
  126. }
  127. /**
  128. * ExecutionAction executes the required methods
  129. */
  130. function executionAction (&$amfbody)
  131. {
  132. $specialHandling = $amfbody->getSpecialHandling();
  133. if (!$amfbody->isSpecialHandling() || $amfbody->isSpecialHandling(array('describeService', 'pageFetch', 'RemotingMessage')))
  134. {
  135. $construct = &$amfbody->getClassConstruct();
  136. $method = $amfbody->methodName;
  137. $args = $amfbody->getValue();
  138. if($specialHandling == 'describeService')
  139. {
  140. include_once(AMFPHP_BASE . "util/DescribeService.php");
  141. $ds = new DescribeService();
  142. $results = $ds->describe($construct, $amfbody->className);
  143. }
  144. else if($specialHandling == 'pageFetch')
  145. {
  146. $args[count($args) - 2] = $args[count($args) - 2] - 1;
  147. $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args);
  148. $results = array("cursor" => $args[count($args) - 2] + 1,
  149. "data" => $dataset);
  150. $amfbody->setMetadata('type', '__DYNAMIC_PAGE__');
  151. }
  152. else
  153. {
  154. /*
  155. if(isset($construct->methodTable[$method]['pagesize']))
  156. {
  157. //Check if counting method was overriden
  158. if(isset($construct->methodTable[$method]['countMethod']))
  159. {
  160. $counter = $construct->methodTable[$method]['countMethod'];
  161. }
  162. else
  163. {
  164. $counter = $method . '_count';
  165. }
  166. $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args); // do the magic
  167. $count = Executive::doMethodCall($amfbody, $construct, $counter, $args);
  168. //Include the wrapper
  169. $results = array('class' => $amfbody->uriClassPath,
  170. 'method' => $amfbody->methodName,
  171. 'count' => $count,
  172. "args" => $args,
  173. "data" => $dataset);
  174. $amfbody->setMetadata('type', '__DYNAMIC_PAGEABLE_RESULTSET__');
  175. $amfbody->setMetadata('pagesize', $construct->methodTable[$method]['pagesize']);
  176. */
  177. //}
  178. //else
  179. //{
  180. //The usual
  181. $time = microtime_float();
  182. $results = Executive::doMethodCall($amfbody, $construct, $method, $args); // do the magic
  183. global $amfphp;
  184. $amfphp['callTime'] += microtime_float() - $time;
  185. //}
  186. }
  187. if($results !== '__amfphp_error')
  188. {
  189. if($specialHandling == 'RemotingMessage')
  190. {
  191. $wrapper = new AcknowledgeMessage($amfbody->getMetadata("messageId"),
  192. $amfbody->getMetadata("clientId"));
  193. $wrapper->body = $results;
  194. $amfbody->setResults($wrapper);
  195. }
  196. else
  197. {
  198. $amfbody->setResults($results);
  199. }
  200. $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
  201. }
  202. return false;
  203. }
  204. elseif($specialHandling == 'Ping')
  205. {
  206. $wrapper = new AcknowledgeMessage($amfbody->getMetadata("messageId"),
  207. $amfbody->getMetadata("clientId"));
  208. $amfbody->setResults($wrapper);
  209. $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
  210. }
  211. else if($specialHandling == 'pageRelease')
  212. {
  213. //Ignore PageAbleResult.release
  214. $amfbody->setResults(true);
  215. $amfbody->setMetaData('type', 'boolean');
  216. $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
  217. return false;
  218. }
  219. return true;
  220. }
  221. ?>