soap.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.webservices
  5. */
  6. //require_once '../inc/global.inc.php';
  7. require_once(dirname(__FILE__).'/webservice.php');
  8. $libpath = api_get_path(LIBRARY_PATH);
  9. /**
  10. * SOAP error handler. Handles an error sending a SOAP fault
  11. */
  12. class WSSoapErrorHandler implements WSErrorHandler {
  13. /**
  14. * Handles the error by sending a SOAP fault through the server
  15. *
  16. * @param WSError Error to handle
  17. */
  18. public function handle($error) {
  19. $server = WSSoapServer::singleton();
  20. $server->fault(strval($error->code), $error->message);
  21. }
  22. }
  23. /**
  24. * SOAP server wrapper implementing a Singleton
  25. */
  26. class WSSoapServer {
  27. /**
  28. * SOAP server instance
  29. *
  30. * @var soap_server
  31. */
  32. private static $_instance;
  33. /**
  34. * Private constructor
  35. */
  36. private function __construct() {
  37. }
  38. /**
  39. * Singleton method
  40. */
  41. public static function singleton() {
  42. if(!isset(self::$_instance)) {
  43. self::$_instance = new soap_server();
  44. // Set the error handler
  45. WSError::setErrorHandler(new WSSoapErrorHandler());
  46. // Configure the service
  47. self::$_instance->configureWSDL('WSService', 'urn:WSService');
  48. }
  49. return self::$_instance;
  50. }
  51. }
  52. $s = WSSoapServer::singleton();
  53. $s->wsdl->addComplexType(
  54. 'result',
  55. 'complexType',
  56. 'struct',
  57. 'all',
  58. '',
  59. array(
  60. 'code' => array('name' => 'code', 'type' => 'xsd:int'),
  61. 'message' => array('name' => 'message', 'type' => 'xsd:string')
  62. )
  63. );
  64. $s->wsdl->addComplexType(
  65. 'extras',
  66. 'complexType',
  67. 'struct',
  68. 'all',
  69. '',
  70. array(
  71. 'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
  72. 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
  73. )
  74. );
  75. $s->wsdl->addComplexType(
  76. 'extra_field',
  77. 'complexType',
  78. 'array',
  79. '',
  80. 'SOAP-ENC:Array',
  81. array(),
  82. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:extras[]')),'tns:extras'
  83. );
  84. /*
  85. $s->wsdl->addComplexType(
  86. 'extra_field',
  87. 'complexType',
  88. 'struct',
  89. 'all',
  90. '',
  91. array(
  92. 'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
  93. 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
  94. )
  95. );
  96. */
  97. $s->register(
  98. 'WS.test',
  99. array(),
  100. array('return' => 'xsd:string')
  101. );
  102. require_once(dirname(__FILE__).'/soap_user.php');
  103. require_once(dirname(__FILE__).'/soap_course.php');
  104. require_once(dirname(__FILE__).'/soap_session.php');
  105. require_once(dirname(__FILE__).'/soap_report.php');
  106. // Use the request to (try to) invoke the service
  107. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  108. $s->service($HTTP_RAW_POST_DATA);