Actions.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. function deserializationAction(&$body)
  3. {
  4. $args = $body->getValue();
  5. $target = $args[0];
  6. $baseClassPath = $GLOBALS['amfphp']['classPath'];
  7. $lpos = strrpos($target, '.');
  8. $methodname = substr($target, $lpos + 1);
  9. $trunced = substr($target, 0, $lpos);
  10. $lpos = strrpos($trunced, ".");
  11. if ($lpos === false) {
  12. $classname = $trunced;
  13. $uriclasspath = $trunced . ".php";
  14. $classpath = $baseClassPath . $trunced . ".php";
  15. } else {
  16. $classname = substr($trunced, $lpos + 1);
  17. $classpath = $baseClassPath . str_replace(".", "/", $trunced) . ".php"; // removed to strip the basecp out of the equation here
  18. $uriclasspath = str_replace(".", "/", $trunced) . ".php"; // removed to strip the basecp out of the equation here
  19. }
  20. $body->methodName = $methodname;
  21. $body->className = $classname;
  22. $body->classPath = $classpath;
  23. $body->uriClassPath = $uriclasspath;
  24. //Now deserialize the arguments
  25. array_shift($args);
  26. $actualArgs = array();
  27. foreach($args as $key => $value)
  28. {
  29. //Look at the value to see if it is JSON-encoded
  30. $value = urldecode($value);
  31. if($value != "")
  32. {
  33. if($value[0] != '[' && $value[0] != '{' && $value != "null" && $value != "false" && $value != "true")
  34. {
  35. //check to see if it is a number
  36. $char1 = ord($value[0]);
  37. if($char1 >= 0x30 && $char1 <= 0x39)
  38. {
  39. //Then this is a number
  40. $value = json_decode($value, true);
  41. } //Else leave value as is
  42. }
  43. else
  44. {
  45. $value = json_decode($value, true);
  46. }
  47. }
  48. $actualArgs[] = $value;
  49. }
  50. $body->setValue($actualArgs);
  51. }
  52. function executionAction(& $body)
  53. {
  54. $classConstruct = &$body->getClassConstruct();
  55. $methodName = $body->methodName;
  56. $args = $body->getValue();
  57. $output = Executive::doMethodCall($body, &$classConstruct, $methodName, $args);
  58. if($output !== "__amfphp_error")
  59. {
  60. $body->setResults($output);
  61. }
  62. }
  63. function serializationAction(& $body)
  64. {
  65. //Take the raw response
  66. $rawResponse = & $body->getResults();
  67. adapterMap($rawResponse);
  68. //Now serialize it
  69. $encodedResponse = json_encode($rawResponse);
  70. if(count(NetDebug::getTraceStack()) > 0)
  71. {
  72. $trace = "/*" . implode("\n", NetDebug::getTraceStack()) . "*/";
  73. $encodedResponse = $trace . "\n" . $encodedResponse;
  74. }
  75. $body->setResults($encodedResponse);
  76. }
  77. if(!function_exists("json_encode"))
  78. {
  79. include_once(AMFPHP_BASE . "shared/util/JSON.php");
  80. function json_encode($val)
  81. {
  82. $json = new Services_JSON();
  83. return $json->encode($val);
  84. }
  85. function json_decode($val, $asAssoc = FALSE)
  86. {
  87. if($asAssoc)
  88. {
  89. $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  90. }
  91. else
  92. {
  93. $json = new Services_JSON();
  94. }
  95. return $json->decode($val);
  96. }
  97. }
  98. ?>