wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.RemotingFacade.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id$
18  */
19 require_once(BASE."wcmf/lib/util/class.Log.php");
20 require_once(BASE."wcmf/lib/presentation/class.Request.php");
21 require_once(BASE."wcmf/lib/presentation/class.Response.php");
22 require_once(BASE."wcmf/lib/remoting/class.HTTPClient.php");
23 require_once(BASE."wcmf/lib/remoting/class.RPCClient.php");
24 require_once(BASE."wcmf/lib/util/class.ObjectFactory.php");
25 
26 /**
27  * @class RemotingFacade
28  * @ingroup Remoting
29  * @brief RemotingFacade is used to communicate with other wCMF instances.
30  *
31  * @author ingo herwig <ingo@wemove.com>
32  */
34 {
35  private $_clients = array();
36  private $_users = array();
37 
38  /**
39  * Get the singleton instance.
40  * @return A reference to a RemotingFacade instance
41  */
42  function &getInstance()
43  {
44  static $instance = null;
45 
46  if (!isset($instance))
47  $instance = new RemotingFacade();
48 
49  return $instance;
50  }
51  /**
52  * Send a request to the server identified by serverKey.
53  * @param serverKey An entry in the configuration section 'remoteserver'
54  * @param request A Request instance
55  * @return A Response instance
56  */
57  function doCall($serverKey, $request)
58  {
59  $client = $this->getClient($serverKey);
60  if ($client)
61  {
62  $response = $client->call($request);
63  return $response;
64  }
65  return new Response();
66  }
67  /**
68  * Get a client instance for a given server key
69  * @param serverKey An entry in the configuration section 'remoteserver'
70  * @return A client instance or null
71  */
72  private function getClient($serverKey)
73  {
74  if (!isset($this->_clients[$serverKey]))
75  {
76  $parser = &InifileParser::getInstance();
77  if (($serverDef = $parser->getValue($serverKey, 'remoteserver')) !== false)
78  {
79  // get remote the user
80  $user = $this->getRemoteUser($serverKey);
81 
82  $client = null;
83  if (strpos($serverDef, 'http://') === 0 || strpos($serverDef, 'https://') === 0) {
84  $client = new HTTPClient($serverDef, $user);
85  }
86  else {
87  $client = new RPCClient($serverDef, $user);
88  }
89  $this->_clients[$serverKey] = $client;
90  }
91  else
92  {
93  WCMFException::throwEx("The remote server with key '".$serverKey."' is unknown.\n".
94  $parser->getErrorMsg(), __FILE__, __LINE__);
95  return null;
96  }
97  }
98  return $this->_clients[$serverKey];
99  }
100  /**
101  * Get the remote user name for a given server key
102  * @param serverKey An entry in the configuration section 'remoteuser'
103  * @return A user instance
104  */
105  private function getRemoteUser($serverKey)
106  {
107  if (!isset($this->_users[$serverKey]))
108  {
109  $parser = &InifileParser::getInstance();
110  if (($remoteLogin = $parser->getValue($serverKey, 'remoteuser')) !== false)
111  {
112  $objectFactory = &ObjectFactory::getInstance();
113  $userManager = &$objectFactory->createInstanceFromConfig('implementation', 'UserManager');
114  $user = &$userManager->getUser($remoteLogin);
115  if ($user != null) {
116  $this->_users[$serverKey] = $user;
117  }
118  else
119  {
120  WCMFException::throwEx("The remote user with login '".$remoteLogin."' does not exist.\n", __FILE__, __LINE__);
121  return null;
122  }
123  }
124  else
125  {
126  WCMFException::throwEx("The remote user with key '".$serverKey."' is unknown.\n".
127  $parser->getErrorMsg(), __FILE__, __LINE__);
128  return null;
129  }
130  }
131  return $this->_users[$serverKey];
132  }
133 }
134 ?>
RemotingFacade is used to communicate with other wCMF instances.
RPCClient is used to do calls to other wCMF instances on the same maschine.
doCall($serverKey, $request)
throwEx($message, $file='', $line='')
HTTPClient is used to do calls to other wCMF instances over HTTP.
Response holds the response values that are used as output from Controller instances. It is typically instantiated by the ActionMapper instance and filled during Controller execution.