1: <?php
2: /**
3: *
4: * @package XCube
5: * @version $Id: XCube_ServiceManager.class.php,v 1.3 2008/10/12 04:30:27 minahito Exp $
6: * @copyright Copyright 2005-2007 XOOPS Cube Project <https://github.com/xoopscube/legacy>
7: * @license https://github.com/xoopscube/legacy/blob/master/docs/bsd_licenses.txt Modified BSD license
8: *
9: */
10:
11: if (!defined('XCUBE_CORE_PATH')) define('XCUBE_CORE_PATH', dirname(__FILE__));
12:
13: require_once XCUBE_CORE_PATH . '/XCube_Delegate.class.php';
14:
15: class XCube_ServiceUtils
16: {
17: function isXSD($typeName)
18: {
19: if ($typeName == 'string' || $typeName == 'int') {
20: return true;
21: }
22:
23: return false;
24: }
25: }
26:
27: /**
28: * This class manages XCube_Service instances, searches these, creates a much
29: * client instance. Now, the purpose of this class is for inside of own XOOPS
30: * site. In other words, this class doesn't work for publishing web services.
31: * About these separated working, the core team shall examine.
32: *
33: * XCube namespace can't contain the SOAP library directly. Delegate mechanism
34: * is good for this class. This class creates a client instance which to
35: * connect to a service, with following the kind of the service. For example,
36: * if the specified service is really web service, SOAP client has to be
37: * created. But, if the service is a virtual service of XCube, virtual client
38: * has to be created.
39: */
40: class XCube_ServiceManager
41: {
42: /**
43: * Array of XCube_Service instances.
44: *
45: * @var Array
46: */
47: var $mServices = array();
48:
49: /**
50: * @var XCube_Delegate
51: * @param &$client
52: * @param $service
53: */
54: var $mCreateClient = null;
55:
56: /**
57: * @var XCube_Delegate
58: */
59: var $mCreateServer = null;
60:
61: function XCube_ServiceManager()
62: {
63: $this->mCreateClient = new XCube_Delegate();
64: $this->mCreateClient->register("XCube_ServiceManager.CreateClient");
65:
66: $this->mCreateServer = new XCube_Delegate();
67: $this->mCreateServer->register("XCube_ServiceManager.CreateServer");
68: }
69:
70: /**
71: * Add service object. $name must be unique in the list of service. If the
72: * service which has the same name, is a member of the list, return false.
73: *
74: * @param $name string
75: * @param $service XCube_Service
76: * @return bool
77: */
78: function addService($name, &$service)
79: {
80: if (isset($this->mServices[$name])) {
81: return false;
82: }
83:
84: $this->mServices[$name] =& $service;
85:
86: return true;
87: }
88:
89: /**
90: * Add WSDL URL. $name must be unique in the list of service. If the
91: * service which has the same name, is a member of the list, return false.
92: *
93: */
94: function addWSDL($name, $url)
95: {
96: if (isset($this->mServices[$name])) {
97: return false;
98: }
99:
100: $this->mServices[$name] =& $url;
101:
102: return true;
103: }
104:
105: /**
106: * This member function will be removed at beta version.
107: *
108: * @deprecated
109: * @see XCube_ServiceManager::addService()
110: */
111: function addXCubeService($name, &$service)
112: {
113: return $this->addService($name, $service);
114: }
115:
116: function &getService($name)
117: {
118: $ret = null;
119:
120: if (isset($this->mServices[$name])) {
121: return $this->mServices[$name];
122: }
123:
124: return $ret;
125: }
126:
127: /**
128: * This member function will be removed at beta version.
129: *
130: * @deprecated
131: * @see XCube_ServiceManager::getService()
132: */
133: function &searchXCubeService($name)
134: {
135: return $this->getService($name);
136: }
137:
138: /**
139: * Create client instance which to connect to a service, with following the
140: * kind of the service. Then return that instance. For example, if the
141: * specified service is really web service, SOAP client has to be created.
142: * But, if the service is a virtual service of XCube, virtual client has to
143: * be created.
144: */
145: function &createClient(&$service)
146: {
147: $client = null;
148: $this->mCreateClient->call(new XCube_Ref($client), new XCube_Ref($service));
149:
150: return $client;
151: }
152:
153: function &createServer(&$service)
154: {
155: $server = null;
156: $this->mCreateServer->call(new XCube_Ref($server), new XCube_Ref($service));
157:
158: return $server;
159: }
160: }
161:
162: ?>