SOAPController.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
15 
16 /**
17  * Global server instance used by the generated soap interface
18  */
19 $server = null;
20 
21 /**
22  * SOAPController handles SOAP requests. The controller delegates action
23  * processing to a global instance of wcmf::lib::service::SoapServer.
24  *
25  * The controller supports the following actions:
26  *
27  * <div class="controller-action">
28  * <div> __Action__ _default_ </div>
29  * <div>
30  * Handle action according to soap request.
31  * </div>
32  * </div>
33  *
34  * The controller expects the definition of the soap interface in a file called
35  * __soap-interface.php__ in the application directory. The definition is done
36  * by adding types and methods to the global `$server` instance
37  *
38  @code
39  // add type to soap interface
40  $server->wsdl->addComplexType(...);
41 
42  // add method to soap interface
43  $server->register();
44  @endcode
45  *
46  * @see http://sourceforge.net/projects/nusoap/
47  *
48  * @author ingo herwig <ingo@wemove.com>
49  */
50 class SOAPController extends Controller {
51 
52  /**
53  * @see Controller::doExecute()
54  */
55  protected function doExecute($method=null) {
56  global $server;
57 
58  // instantiate server
59  $server = new SoapServer();
60 
61  // register search method
62  $server->register('search',
63  ['query' => 'xsd:string'], ['return' => 'tns:SearchResultList'],
64  $server::TNS, $server->wsdl->endpoint.'#search', 'document', 'literal'
65  );
66 
67  // include the generated interface
68  require("soap-interface.php");
69 
70  // invoke the service
71  $server->service(file_get_contents("php://input"));
72 
73  // set the response
74  $response = $this->getResponse();
75  $response->setFormat('generic');
76  $response->setHeaders($server->getResponseHeaders());
77  $response->setValue('body', $server->getResponsePayload());
78  }
79 
80  /**
81  * Search
82  * @param $query The search term
83  * @return Array of SearchResultItem on success
84  */
85  public static function search($query) {
86  global $server;
87  $response = $server->doCall('search', ['query' => $query]);
88  $result = [];
89  foreach ($response->getValue('list') as $item) {
90  $result[] = ['type' => $item['type'], 'oid' => $item['oid'],
91  'displayValue' => $item['displayValue'], 'summary' => $item['summary']
92  ];
93  }
94  return ['return' => $result];
95  }
96 }
97 ?>
SoapServer extends nusoap server to actually process requests inside the application context.
Definition: SoapServer.php:30
$server
Global server instance used by the generated soap interface.
Application controllers.
Definition: namespaces.php:3
Controller is the base class of all controllers.
Definition: Controller.php:49
SOAPController handles SOAP requests.
getResponse()
Get the Response instance.
Definition: Controller.php:259