php5Executive.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * The Executive class is responsible for executing the remote service method and returning it's value.
  4. *
  5. * Currently the executive class is a complicated chain of filtering events testing for various cases and
  6. * handling them. Future versions of this class will probably be broken up into many helper classes which will
  7. * use a delegation or chaining pattern to make adding new exceptions or handlers more modular. This will
  8. * become even more important if developers need to make their own custom header handlers.
  9. *
  10. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11. * @copyright (c) 2003 amfphp.org
  12. * @package flashservices
  13. * @subpackage app
  14. * @author Musicman original design
  15. * @author Justin Watkins Gateway architecture, class structure, datatype io additions
  16. * @author John Cowen Datatype io additions, class structure
  17. * @author Klaasjan Tukker Modifications, check routines
  18. * @version $Id: php5Executive.php,v 1.3 2005/07/05 07:40:50 pmineault Exp $
  19. */
  20. class Executive {
  21. /**
  22. * The built instance of the service class
  23. *
  24. * @access private
  25. * @var object
  26. */
  27. var $_classConstruct;
  28. /**
  29. * The method name to execute
  30. *
  31. * @access private
  32. * @var string
  33. */
  34. var $_methodname;
  35. /**
  36. * The arguments to pass to the executed method
  37. *
  38. * @access private
  39. * @var mixed
  40. */
  41. var $_arguments;
  42. function Executive() {
  43. }
  44. /**
  45. * The main method of the executive class.
  46. *
  47. * @param array $a Arguments to pass to the method
  48. * @return mixed The results from the method operation
  49. */
  50. function doMethodCall(&$bodyObj, &$object, $method, $args)
  51. {
  52. try
  53. {
  54. $output = Executive::deferredMethodCall($bodyObj, $object, $method, $args);
  55. }
  56. catch(Exception $fault)
  57. {
  58. if(get_class($fault) == "VerboseException")
  59. {
  60. $ex = new MessageException($fault->code, $fault->getMessage(), $fault->file, $fault->line, 'AMFPHP_RUNTIME_ERROR');
  61. }
  62. else
  63. {
  64. $code = "AMFPHP_RUNTIME_ERROR";
  65. if($fault->getCode() != 0)
  66. {
  67. $code = $fault->getCode();
  68. }
  69. $ex = new MessageException(E_USER_ERROR, $fault->getMessage(), $fault->getFile(), $fault->getLine(), $code);
  70. }
  71. MessageException::throwException($bodyObj, $ex);
  72. $output = '__amfphp_error';
  73. }
  74. return $output;
  75. }
  76. /**
  77. * Builds a class using a class name
  78. * If there is a failure, catch the error and return to caller
  79. */
  80. function buildClass(&$bodyObj, $className)
  81. {
  82. global $amfphp;
  83. if(isset($amfphp['classInstances'][$className]))
  84. {
  85. return $amfphp['classInstances'][$className];
  86. }
  87. try
  88. {
  89. $construct = new $className($className);
  90. $amfphp['classInstances'][$className] = & $construct;
  91. }
  92. catch(Exception $fault)
  93. {
  94. //When constructing a class, getLine and getFile don't refer to the appropriate thing,
  95. //hence this hack
  96. $ex = new MessageException(E_USER_ERROR, $fault->getMessage(), $bodyObj->classPath, 'Undetermined line in constructor', 'AMFPHP_BUILD_ERROR');
  97. MessageException::throwException($bodyObj, $ex);
  98. $construct = '__amfphp_error';
  99. }
  100. return $construct;
  101. }
  102. /**
  103. * We are using a deferred metho call instead of directly
  104. * calling the method because of a strange bug with throwing exceptions within
  105. * an error handler which seems to break the convential rule for working with exceptions
  106. * Nesting function calls seems to solve the problem, but not nesting try...catch
  107. */
  108. function deferredMethodCall(&$bodyObj, &$object, $method, $args)
  109. {
  110. try
  111. {
  112. if($object === NULL)
  113. {
  114. $output = call_user_func_array ($method, $args);
  115. }
  116. else
  117. {
  118. $output = call_user_func_array (array(&$object, $method), $args);
  119. }
  120. }
  121. catch(Exception $fault)
  122. {
  123. if(get_class($fault) == "VerboseException")
  124. {
  125. $ex = new MessageException($fault->code, $fault->getMessage(), $fault->file, $fault->line, 'AMFPHP_RUNTIME_ERROR');
  126. }
  127. else
  128. {
  129. $code = "AMFPHP_RUNTIME_ERROR";
  130. if($fault->getCode() != 0)
  131. {
  132. $code = $fault->getCode();
  133. }
  134. $ex = new MessageException(E_USER_ERROR, $fault->getMessage(), $fault->getFile(), $fault->getLine(), $code);
  135. }
  136. $output = '__amfphp_error';
  137. MessageException::throwException($bodyObj, $ex);
  138. }
  139. return $output;
  140. }
  141. /**
  142. * Include a class
  143. * If there is an error, catch and return to caller
  144. */
  145. function includeClass(&$bodyObj, $location)
  146. {
  147. $included = false;
  148. try
  149. {
  150. include_once($location);
  151. $included = true;
  152. }
  153. catch(Exception $fault)
  154. {
  155. $included = false;
  156. if(get_class($fault) == "VerboseException")
  157. {
  158. $ex = new MessageException($fault->code, $fault->getMessage(), $fault->file, $fault->line, 'AMFPHP_INCLUDE_ERROR');
  159. }
  160. else
  161. {
  162. $ex = new MessageException(E_USER_ERROR, $fault->getMessage(), $fault->getFile(), $fault->getLine(), 'AMFPHP_INCLUDE_ERROR');
  163. }
  164. MessageException::throwException($bodyObj, $ex);
  165. }
  166. return $included;
  167. }
  168. }
  169. ?>