1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: class Horde_Core_Factory_KolabServer extends Horde_Core_Factory_Base
29: {
30: 31:
32: public function __construct(Horde_Injector $injector)
33: {
34: parent::__construct($injector);
35: $this->_setup();
36: }
37:
38: 39: 40: 41: 42:
43: private function _setup()
44: {
45: $this->_setupConfiguration();
46: $this->_setupConnection();
47: $this->_setupObjects();
48: $this->_setupSearch();
49: $this->_setupSchema();
50: $this->_setupStructure();
51: $this->_setupServer();
52: }
53:
54: 55: 56: 57: 58:
59: private function _setupConfiguration()
60: {
61: $configuration = array();
62:
63:
64: if (!empty($GLOBALS['conf']['kolab']['ldap'])) {
65: $configuration = $GLOBALS['conf']['kolab']['ldap'];
66: }
67: if (!empty($GLOBALS['conf']['kolab']['server'])) {
68: $configuration = $GLOBALS['conf']['kolab']['server'];
69: }
70:
71: if (isset($configuration['server'])) {
72: $configuration['hostspec'] = $configuration['server'];
73: unset($configuration['server']);
74: }
75:
76: if (isset($configuration['phpdn'])) {
77: $configuration['binddn'] = $configuration['phpdn'];
78: unset($configuration['phpdn']);
79: }
80:
81: if (isset($configuration['phppw'])) {
82: $configuration['bindpw'] = $configuration['phppw'];
83: unset($configuration['phppw']);
84: }
85:
86: $this->_injector->setInstance(
87: 'Horde_Kolab_Server_Configuration', $configuration
88: );
89: }
90:
91: 92: 93: 94: 95:
96: private function _setupConnection()
97: {
98: $this->_injector->bindFactory(
99: 'Horde_Kolab_Server_Connection',
100: 'Horde_Core_Factory_KolabServer',
101: 'getConnection'
102: );
103: }
104:
105: 106: 107: 108: 109:
110: private function _setupObjects()
111: {
112: $this->_injector->bindImplementation(
113: 'Horde_Kolab_Server_Objects_Interface',
114: 'Horde_Kolab_Server_Objects_Base'
115: );
116: }
117:
118: 119: 120: 121: 122:
123: private function _setupSearch()
124: {
125: $this->_injector->bindImplementation(
126: 'Horde_Kolab_Server_Search_Interface',
127: 'Horde_Kolab_Server_Search_Base'
128: );
129: }
130:
131: 132: 133: 134: 135:
136: private function _setupSchema()
137: {
138: $this->_injector->bindImplementation(
139: 'Horde_Kolab_Server_Schema_Interface',
140: 'Horde_Kolab_Server_Schema_Base'
141: );
142: }
143:
144: 145: 146: 147: 148:
149: private function _setupStructure()
150: {
151: $configuration = $this->getConfiguration();
152: if (!isset($configuration['structure']['driver'])) {
153: $driver = 'Horde_Kolab_Server_Structure_Kolab';
154: } else {
155: $driver = $configuration['structure']['driver'];
156: }
157:
158: $this->_injector->bindImplementation(
159: 'Horde_Kolab_Server_Structure_Interface', $driver
160: );
161: }
162:
163: 164: 165: 166: 167:
168: private function _setupServer()
169: {
170: $this->_injector->bindFactory(
171: 'Horde_Kolab_Server_Interface',
172: 'Horde_Core_Factory_KolabServer',
173: 'getServer'
174: );
175: }
176:
177: 178: 179: 180: 181:
182: public function getConnection()
183: {
184: $configuration = $this->_injector->getInstance('Horde_Kolab_Server_Configuration');
185: if (empty($configuration['mock'])) {
186: if (!isset($configuration['basedn'])) {
187: $configuration['basedn'] = '';
188: }
189:
190: $configuration['cache'] = $this->_injector->getInstance('Horde_Cache');
191:
192: $ldap_read = new Horde_Ldap($configuration);
193: if (isset($configuration['host_master'])) {
194: $configuration['hostspec'] = $configuration['host_master'];
195: $ldap_write = new Horde_Ldap($configuration);
196: $connection = new Horde_Kolab_Server_Connection_Splittedldap(
197: $ldap_read, $ldap_write
198: );
199: } else {
200: $connection = new Horde_Kolab_Server_Connection_Simpleldap(
201: $ldap_read
202: );
203: }
204: return $connection;
205: } else {
206: if (isset($configuration['data'])) {
207: $data = $configuration['data'];
208: } else {
209: $data = array();
210: }
211: $connection = new Horde_Kolab_Server_Connection_Mock(
212: new Horde_Kolab_Server_Connection_Mock_Ldap(
213: $configuration, $data
214: )
215: );
216: return $connection;
217: }
218: }
219:
220: 221: 222: 223: 224:
225: public function getConfiguration()
226: {
227: return $this->_injector->getInstance('Horde_Kolab_Server_Configuration');
228: }
229:
230: 231: 232: 233: 234:
235: public function getServer()
236: {
237: $configuration = $this->getConfiguration();
238: if (!isset($configuration['basedn'])) {
239: $configuration['basedn'] = '';
240: }
241:
242: $connection = $this->getConnection();
243:
244: if (!isset($configuration['filter'])) {
245: $server = new Horde_Kolab_Server_Ldap_Standard(
246: $connection,
247: $configuration['basedn']
248: );
249: } else {
250: $server = new Horde_Kolab_Server_Ldap_Filtered(
251: $connection,
252: $configuration['basedn'],
253: $configuration['filter']
254: );
255: }
256:
257: if (isset($configuration['map'])) {
258: $server = new Horde_Kolab_Server_Decorator_Map(
259: $server, $configuration['map']
260: );
261: }
262:
263: if (isset($configuration['debug']) || isset($configuration['log'])) {
264: $server = new Horde_Kolab_Server_Decorator_Log(
265: $server, $this->_injector->getInstance('Horde_Log_Logger')
266: );
267: }
268:
269: if (isset($configuration['debug']) || isset($configuration['count'])) {
270: $server = new Horde_Kolab_Server_Decorator_Count(
271: $server, $this->_injector->getInstance('Horde_Log_Logger')
272: );
273: }
274:
275: if (!empty($configuration['cleanup'])) {
276: $server = new Horde_Kolab_Server_Decorator_Clean(
277: $server
278: );
279: }
280: return $server;
281: }
282:
283: 284: 285: 286: 287:
288: public function getObjects()
289: {
290: return $this->_injector->getInstance(
291: 'Horde_Kolab_Server_Objects_Interface'
292: );
293: }
294:
295: 296: 297: 298: 299: 300:
301: public function getStructure()
302: {
303: return $this->_injector->getInstance(
304: 'Horde_Kolab_Server_Structure_Interface'
305: );
306: }
307:
308: 309: 310: 311: 312:
313: public function getSearch()
314: {
315: return $this->_injector->getInstance(
316: 'Horde_Kolab_Server_Search_Interface'
317: );
318: }
319:
320: 321: 322: 323: 324:
325: public function getSchema()
326: {
327: return $this->_injector->getInstance(
328: 'Horde_Kolab_Server_Schema_Interface'
329: );
330: }
331:
332: 333: 334: 335: 336: 337: 338:
339: public function create()
340: {
341: return new Horde_Kolab_Server_Composite(
342: $this->getServer(),
343: $this->getObjects(),
344: $this->getStructure(),
345: $this->getSearch(),
346: $this->getSchema()
347: );
348: }
349: }
350: