cm_soap.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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__.'/cm_webservice.php';
  8. /**
  9. * SOAP error handler. Handles an error sending a SOAP fault.
  10. */
  11. class WSCMSoapErrorHandler implements WSCMErrorHandler
  12. {
  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. {
  20. $server = WSCMSoapServer::singleton();
  21. $server->fault(strval($error->code), $error->message);
  22. }
  23. }
  24. /**
  25. * SOAP server wrapper implementing a Singleton.
  26. */
  27. class WSCMSoapServer
  28. {
  29. /**
  30. * SOAP server instance.
  31. *
  32. * @var soap_server
  33. */
  34. private static $_instance;
  35. /**
  36. * Private constructor.
  37. */
  38. public function __construct()
  39. {
  40. }
  41. /**
  42. * Singleton method.
  43. */
  44. public static function singleton()
  45. {
  46. if (!isset(self::$_instance)) {
  47. self::$_instance = new soap_server();
  48. // Set the error handler
  49. WSCMError::setErrorHandler(new WSCMSoapErrorHandler());
  50. // Configure the service
  51. self::$_instance->configureWSDL('WSCMService', 'urn:WSCMService');
  52. }
  53. return self::$_instance;
  54. }
  55. }
  56. $s = WSCMSoapServer::singleton();
  57. $s->wsdl->addComplexType(
  58. 'result',
  59. 'complexType',
  60. 'struct',
  61. 'all',
  62. '',
  63. [
  64. 'code' => ['name' => 'code', 'type' => 'xsd:int'],
  65. 'message' => ['name' => 'message', 'type' => 'xsd:string'],
  66. ]
  67. );
  68. $s->wsdl->addComplexType(
  69. 'extra_field',
  70. 'complexType',
  71. 'struct',
  72. 'all',
  73. '',
  74. [
  75. 'field_name' => ['name' => 'field_name', 'type' => 'xsd:string'],
  76. 'field_value' => ['name' => 'field_value', 'type' => 'xsd:string'],
  77. ]
  78. );
  79. $s->register(
  80. 'WSCM.verifyUserPass',
  81. [
  82. 'username' => 'xsd:string',
  83. 'password' => 'xsd:string',
  84. ],
  85. ['return' => 'xsd:string']
  86. );
  87. $s->register(
  88. 'WSCM.encryptPass',
  89. ['password' => 'xsd:string'],
  90. ['return' => 'xsd:string']
  91. );
  92. $s->register(
  93. 'WSCM.test',
  94. [],
  95. ['return' => 'xsd:string'],
  96. 'urn:WSCMService',
  97. '',
  98. '',
  99. '',
  100. ''
  101. );
  102. require_once __DIR__.'/cm_soap_inbox.php';
  103. require_once __DIR__.'/cm_soap_user.php';
  104. require_once __DIR__.'/cm_soap_courses.php';
  105. require_once __DIR__.'/cm_soap_announcements.php';
  106. require_once __DIR__.'/cm_soap_forum.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);