soap.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. 'extras',
  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->wsdl->addComplexType(
  77. 'extra_field',
  78. 'complexType',
  79. 'array',
  80. '',
  81. 'SOAP-ENC:Array',
  82. array(),
  83. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:extras[]')),'tns:extras'
  84. );
  85. /*
  86. $s->wsdl->addComplexType(
  87. 'extra_field',
  88. 'complexType',
  89. 'struct',
  90. 'all',
  91. '',
  92. array(
  93. 'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
  94. 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
  95. )
  96. );
  97. */
  98. $s->register(
  99. 'WS.test',
  100. array(),
  101. array('return' => 'xsd:string')
  102. );
  103. require_once(dirname(__FILE__).'/soap_user.php');
  104. require_once(dirname(__FILE__).'/soap_course.php');
  105. require_once(dirname(__FILE__).'/soap_session.php');
  106. require_once(dirname(__FILE__).'/soap_report.php');
  107. // Use the request to (try to) invoke the service
  108. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  109. $s->service($HTTP_RAW_POST_DATA);