1: <?php
2: /**
3: * A simple composition of server functionality.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Server
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Server
12: */
13:
14: /**
15: * A simple composition of server functionality.
16: *
17: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Server
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Server
27: */
28: class Horde_Kolab_Server_Composite
29: {
30: /**
31: * The server.
32: *
33: * @var Horde_Kolab_Server_Interface
34: */
35: private $_server;
36:
37: /**
38: * The structure handler for this server.
39: *
40: * @var Horde_Kolab_Server_Structure_Interface
41: */
42: private $_structure;
43:
44: /**
45: * The search handler for this server.
46: *
47: * @var Horde_Kolab_Server_Search_Interface
48: */
49: private $_search;
50:
51: /**
52: * The object handler for this server.
53: *
54: * @var Horde_Kolab_Server_Objects_Interface
55: */
56: private $_objects;
57:
58: /**
59: * The schema handler for this server.
60: *
61: * @var Horde_Kolab_Server_Schema_Interface
62: */
63: private $_schema;
64:
65: /**
66: * Construct a new Horde_Kolab_Server object.
67: *
68: * @param array $params Parameter array.
69: */
70: public function __construct(
71: Horde_Kolab_Server_Interface $server,
72: Horde_Kolab_Server_Objects_Interface $objects,
73: Horde_Kolab_Server_Structure_Interface $structure,
74: Horde_Kolab_Server_Search_Interface $search,
75: Horde_Kolab_Server_Schema_Interface $schema
76: ) {
77: $this->_server = $server;
78: $this->_objects = $objects;
79: $this->_structure = $structure;
80: $this->_search = $search;
81: $this->_schema = $schema;
82:
83: $structure->setComposite($this);
84: $search->setComposite($this);
85: $schema->setComposite($this);
86: $objects->setComposite($this);
87: }
88:
89: /**
90: * Retrieve an object attribute.
91: *
92: * @param string $key The name of the attribute.
93: *
94: * @return mixed The atribute value.
95: *
96: * @throws Horde_Kolab_Server_Exception If the attribute does not exist.
97: */
98: public function __get($key)
99: {
100: $public = array('server', 'objects', 'structure', 'search', 'schema');
101: if (in_array($key, $public)) {
102: $priv_key = '_' . $key;
103: return $this->$priv_key;
104: }
105: throw new Horde_Kolab_Server_Exception(
106: sprintf('Attribute %s not supported!', $key)
107: );
108: }
109:
110: /**
111: * Connect to the server. Use this method if the user name you can provide
112: * does not match a GUID. In this case it will be required to map this user
113: * name first.
114: *
115: * @param string $user The user name.
116: * @param string $pass The password.
117: *
118: * @return NULL.
119: *
120: * @throws Horde_Kolab_Server_Exception If the connection failed.
121: */
122: public function connect($user = null, $pass = null)
123: {
124: /** Bind anonymously first. */
125: $this->server->connectGuid();
126: $guid = $this->search->searchGuidForUidOrMail($user);
127: $this->server->connectGuid($guid, $pass);
128: }
129: }
130: