BasicGateway.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. require_once(AMFPHP_BASE . "shared/app/BasicActions.php");
  3. require_once(AMFPHP_BASE . "shared/app/Constants.php");
  4. require_once(AMFPHP_BASE . "shared/app/Globals.php");
  5. require_once(AMFPHP_BASE . "shared/exception/MessageException.php");
  6. if(AMFPHP_PHP5)
  7. {
  8. include_once(AMFPHP_BASE . "shared/util/CompatPhp5.php");
  9. }
  10. else
  11. {
  12. include_once(AMFPHP_BASE . "shared/util/CompatPhp4.php");
  13. }
  14. /**
  15. * This basic gateway is a base class for all simple RPC types (that is, RPC which doesn't
  16. * allow batching)
  17. */
  18. class BasicGateway
  19. {
  20. function BasicGateway()
  21. {
  22. if(AMFPHP_PHP5)
  23. {
  24. //Set gloriously nice error handling
  25. include_once(AMFPHP_BASE . "shared/app/php5Executive.php");
  26. include_once(AMFPHP_BASE . "shared/exception/php5Exception.php");
  27. }
  28. else
  29. {
  30. //Cry
  31. include_once(AMFPHP_BASE . "shared/app/php4Executive.php");
  32. include_once(AMFPHP_BASE . "shared/exception/php4Exception.php");
  33. }
  34. $this->registerActionChain();
  35. }
  36. /**
  37. * Sets the base path for loading service methods.
  38. *
  39. * Call this method to define the directory to look for service classes in.
  40. * Relative or full paths are acceptable
  41. *
  42. * @param string $path The path the the service class directory
  43. */
  44. function setBaseClassPath($value) {
  45. $path = realpath($value . '/') . '/';
  46. $GLOBALS['amfphp']['classPath'] = $path;
  47. }
  48. function service()
  49. {
  50. //Process the arguments
  51. $body = $this->createBody();
  52. foreach($this->actions as $key => $action)
  53. {
  54. $result = $action($body); // invoke the first filter in the chain
  55. if($result === false)
  56. {
  57. //Go straight to serialization actions
  58. $serAction = 'serializationAction';
  59. $serAction($body);
  60. break;
  61. }
  62. }
  63. echo $body->getResults();
  64. }
  65. /**
  66. * Add a class mapping for adapters
  67. */
  68. function addAdapterMapping($key, $value)
  69. {
  70. $GLOBALS['amfphp']['adapterMappings'][$key] = $value;
  71. }
  72. /**
  73. * This function should overriden by the gateways
  74. */
  75. function createBody()
  76. {
  77. }
  78. /**
  79. * Create the chain of actions
  80. * Subclass gateway and overwrite to create a custom gateway
  81. */
  82. function registerActionChain()
  83. {
  84. }
  85. }
  86. ?>