1: <?php
2: /**
3: * A decorator to represent a Kolab object attribute that can only be written on
4: * object creation and is immutable afterwards.
5: *
6: * PHP version 5
7: *
8: * @category Kolab
9: * @package Kolab_Server
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_Server
13: */
14:
15: /**
16: * A decorator to represent a Kolab object attribute that can only be written on
17: * object creation and is immutable afterwards.
18: *
19: * Copyright 2008-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_Server
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_Server
29: */
30: class Horde_Kolab_Server_Object_Attribute_Locked
31: extends Horde_Kolab_Server_Object_Attribute_Decorator
32: {
33: /**
34: * Return the new internal state for this attribute.
35: *
36: * @param array $changes The object data that should be updated.
37: *
38: * @return array The resulting internal state.
39: *
40: * @throws Horde_Kolab_Server_Exception If storing the value failed.
41: */
42: public function update(array $changes)
43: {
44: if ($this->_attribute->isEmpty($changes)) {
45: return array();
46: }
47: $changes = $this->_attribute->update($changes);
48: if (!empty($changes) && $this->getObject()->exists()) {
49: throw new Horde_Kolab_Server_Exception(
50: sprintf(
51: "The value for \"%s\" may not be modified on an existing object!",
52: $this->_attribute->getName()
53: )
54: );
55: }
56: return $changes;
57: }
58: }