1: <?php
2: /**
3: * The Horde_Kolab_Storage_Folder_Namespace_Config:: allows to configure the available
4: * IMAP namespaces on the Kolab server.
5: *
6: * PHP version 5
7: *
8: * @category Kolab
9: * @package Kolab_Storage
10: * @author Gunnar Wrobel <wrobel@pardus.de>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Kolab_Storage
13: */
14:
15: /**
16: * The Horde_Kolab_Storage_Folder_Namespace_Config:: allows to configure the available
17: * IMAP namespaces on the Kolab server.
18: *
19: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you
22: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Kolab
25: * @package Kolab_Storage
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28: * @link http://pear.horde.org/index.php?package=Kolab_Storage
29: */
30: class Horde_Kolab_Storage_Folder_Namespace_Config
31: extends Horde_Kolab_Storage_Folder_Namespace
32: {
33: /**
34: * The namespace configuration.
35: *
36: * @var array
37: */
38: protected $configuration;
39:
40: /**
41: * Constructor.
42: *
43: * @param string $user The current user.
44: * @param array $configuration The namespace configuration.
45: */
46: public function __construct($user, array $configuration)
47: {
48: $this->user = $user;
49: $this->configuration = $configuration;
50: parent::__construct($this->_initializeData());
51: }
52:
53: /**
54: * Initialize the namespace elements.
55: *
56: * @return array The namespace elements.
57: */
58: private function _initializeData()
59: {
60: $namespace = array();
61: foreach ($this->configuration as $element) {
62: if ($element['type'] == Horde_Kolab_Storage_Folder_Namespace::SHARED
63: && isset($element['prefix'])) {
64: $namespace_element = new Horde_Kolab_Storage_Folder_Namespace_Element_SharedWithPrefix(
65: $element['name'], $element['delimiter'], $this->user, $element['prefix']
66: );
67: } else {
68: $class = 'Horde_Kolab_Storage_Folder_Namespace_Element_' . ucfirst($element['type']);
69: if (!class_exists($class)) {
70: throw new Horde_Kolab_Storage_Exception(
71: sprintf('Unkown namespace type "%s"', $element['type'])
72: );
73: }
74: $namespace_element = new $class($element['name'], $element['delimiter'], $this->user);
75: }
76: $namespaces[] = $namespace_element;
77: }
78: return $namespaces;
79: }
80:
81: /**
82: * Serialize this object.
83: *
84: * @return string The serialized data.
85: */
86: public function serialize()
87: {
88: return serialize(array($this->user, $this->configuration));
89: }
90:
91: /**
92: * Reconstruct the object from serialized data.
93: *
94: * @param string $data The serialized data.
95: */
96: public function unserialize($data)
97: {
98: list($this->user, $this->configuration) = @unserialize($data);
99: $this->initialize($this->_initializeData());
100: }
101: }