soap.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. require_once $libpath.'nusoap/nusoap.php';
  10. /**
  11. * SOAP error handler. Handles an error sending a SOAP fault
  12. */
  13. class WSSoapErrorHandler implements WSErrorHandler {
  14. /**
  15. * Handles the error by sending a SOAP fault through the server
  16. *
  17. * @param WSError Error to handle
  18. */
  19. public function handle($error) {
  20. $server = WSSoapServer::singleton();
  21. $server->fault(strval($error->code), $error->message);
  22. }
  23. }
  24. /**
  25. * SOAP server wrapper implementing a Singleton
  26. */
  27. class WSSoapServer {
  28. /**
  29. * SOAP server instance
  30. *
  31. * @var soap_server
  32. */
  33. private static $_instance;
  34. /**
  35. * Private constructor
  36. */
  37. private function __construct() {
  38. }
  39. /**
  40. * Singleton method
  41. */
  42. public static function singleton() {
  43. if(!isset(self::$_instance)) {
  44. self::$_instance = new soap_server();
  45. // Set the error handler
  46. WSError::setErrorHandler(new WSSoapErrorHandler());
  47. // Configure the service
  48. self::$_instance->configureWSDL('WSService', 'urn:WSService');
  49. }
  50. return self::$_instance;
  51. }
  52. }
  53. $s = WSSoapServer::singleton();
  54. $s->wsdl->addComplexType(
  55. 'result',
  56. 'complexType',
  57. 'struct',
  58. 'all',
  59. '',
  60. array(
  61. 'code' => array('name' => 'code', 'type' => 'xsd:int'),
  62. 'message' => array('name' => 'message', 'type' => 'xsd:string')
  63. )
  64. );
  65. $s->wsdl->addComplexType(
  66. 'extra_field',
  67. 'complexType',
  68. 'struct',
  69. 'all',
  70. '',
  71. array(
  72. 'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
  73. 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
  74. )
  75. );
  76. $s->register(
  77. 'WS.test',
  78. array(),
  79. array('return' => 'xsd:string')
  80. );
  81. require_once(dirname(__FILE__).'/soap_user.php');
  82. require_once(dirname(__FILE__).'/soap_course.php');
  83. require_once(dirname(__FILE__).'/soap_session.php');
  84. require_once(dirname(__FILE__).'/soap_report.php');
  85. // Use the request to (try to) invoke the service
  86. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  87. $s->service($HTTP_RAW_POST_DATA);