soap.php 2.8 KB

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