File: Composite.php

package info (click to toggle)
php-horde-kolab-server 2.0.5-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 2,056 kB
  • sloc: php: 11,626; xml: 844; sh: 3; makefile: 2
file content (129 lines) | stat: -rw-r--r-- 3,520 bytes parent folder | download | duplicates (4)
1
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
 * A simple composition of server functionality.
 *
 * PHP version 5
 *
 * @category Kolab
 * @package  Kolab_Server
 * @author   Gunnar Wrobel <wrobel@pardus.de>
 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @link     http://pear.horde.org/index.php?package=Kolab_Server
 */

/**
 * A simple composition of server functionality.
 *
 * Copyright 2008-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 *
 * @category Kolab
 * @package  Kolab_Server
 * @author   Gunnar Wrobel <wrobel@pardus.de>
 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @link     http://pear.horde.org/index.php?package=Kolab_Server
 */
class Horde_Kolab_Server_Composite
{
    /**
     * The server.
     *
     * @var Horde_Kolab_Server_Interface
     */
    private $_server;

    /**
     * The structure handler for this server.
     *
     * @var Horde_Kolab_Server_Structure_Interface
     */
    private $_structure;

    /**
     * The search handler for this server.
     *
     * @var Horde_Kolab_Server_Search_Interface
     */
    private $_search;

    /**
     * The object handler for this server.
     *
     * @var Horde_Kolab_Server_Objects_Interface
     */
    private $_objects;

    /**
     * The schema handler for this server.
     *
     * @var Horde_Kolab_Server_Schema_Interface
     */
    private $_schema;

    /**
     * Construct a new Horde_Kolab_Server object.
     *
     * @param array $params Parameter array.
     */
    public function __construct(
        Horde_Kolab_Server_Interface $server,
        Horde_Kolab_Server_Objects_Interface $objects,
        Horde_Kolab_Server_Structure_Interface $structure,
        Horde_Kolab_Server_Search_Interface $search,
        Horde_Kolab_Server_Schema_Interface $schema
    ) {
        $this->_server    = $server;
        $this->_objects   = $objects;
        $this->_structure = $structure;
        $this->_search    = $search;
        $this->_schema    = $schema;

        $structure->setComposite($this);
        $search->setComposite($this);
        $schema->setComposite($this);
        $objects->setComposite($this);
    }

    /**
     * Retrieve an object attribute.
     *
     * @param string $key The name of the attribute.
     *
     * @return mixed The atribute value.
     *
     * @throws Horde_Kolab_Server_Exception If the attribute does not exist.
     */
    public function __get($key)
    {
        $public = array('server', 'objects', 'structure', 'search', 'schema');
        if (in_array($key, $public)) {
            $priv_key = '_' . $key;
            return $this->$priv_key;
        }
        throw new Horde_Kolab_Server_Exception(
            sprintf('Attribute %s not supported!', $key)
        );
    }

    /**
     * Connect to the server. Use this method if the user name you can provide
     * does not match a GUID. In this case it will be required to map this user
     * name first.
     *
     * @param string $user The user name.
     * @param string $pass The password.
     *
     * @return NULL.
     *
     * @throws Horde_Kolab_Server_Exception If the connection failed.
     */
    public function connect($user = null, $pass = null)
    {
        /** Bind anonymously first. */
        $this->server->connectGuid();
        $guid = $this->search->searchGuidForUidOrMail($user);
        $this->server->connectGuid($guid, $pass);
    }
}