1: <?php
2: /**
3: * The base class representing Kolab object attributes.
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: * The base class representing Kolab object attributes.
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_Object_Attribute_Value
29: extends Horde_Kolab_Server_Object_Attribute_Base
30: {
31: /**
32: * Return the value of this attribute.
33: *
34: * @return array The value(s) of this attribute.
35: *
36: * @throws Horde_Kolab_Server_Exception If retrieval of the value failed.
37: */
38: public function value()
39: {
40: $internal = $this->attribute->value();
41: if (isset($internal[$this->name])) {
42: return $internal[$this->name];
43: } else {
44: throw new Horde_Kolab_Server_Exception(sprintf('Missing value %s!', $this->name));
45: }
46: }
47:
48: /**
49: * Indicate that a value will be saved by deleting it from the original data
50: * array.
51: *
52: * @param array &$changes The object data that should be changed.
53: *
54: * @return NULL
55: */
56: public function consume(array &$changes)
57: {
58: if (isset($changes[$this->name])) {
59: unset($changes[$this->name]);
60: }
61: }
62:
63: /**
64: * Return the new internal state for this attribute.
65: *
66: * @param array $changes The object data that should be updated.
67: *
68: * @return array The resulting internal state.
69: *
70: * @throws Horde_Kolab_Server_Exception If storing the value failed.
71: */
72: public function update(array $changes)
73: {
74: if (!$this->isEmpty($changes)) {
75: $value = $changes[$this->name];
76: if (!is_array($value)) {
77: $value = array($value);
78: }
79: return $this->attribute->update($value);
80: }
81: try {
82: $old = $this->attribute->value();
83: return $this->attribute->update(array());
84: } catch (Horde_Kolab_Server_Exception_Novalue $e) {
85: return array();
86: }
87: }
88:
89: }