1: <?php
2: /**
3: * A decorator to represent an object attribute with a default.
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 decorator to represent an object attribute with a default.
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_Default
29: extends Horde_Kolab_Server_Object_Attribute_Decorator
30: {
31: /**
32: * The default value for the attribute.
33: *
34: * @param mixed
35: */
36: private $_default;
37:
38: /**
39: * Constructor
40: *
41: * @param Horde_Kolab_Server_Object_Attribute $attribute The decorated
42: * attribute.
43: * @param mixed $default The default value.
44: */
45: public function __construct(
46: Horde_Kolab_Server_Object_Attribute $attribute,
47: $default
48: ) {
49: $this->_default = $default;
50: parent::__construct($attribute);
51: }
52:
53: /**
54: * Return the new internal state for this attribute.
55: *
56: * @param array $changes The object data that should be updated.
57: *
58: * @return array The resulting internal state.
59: *
60: * @throws Horde_Kolab_Server_Exception If storing the value failed.
61: */
62: public function update(array $changes)
63: {
64: if (!$this->_attribute->getObject()->exists()
65: && !$this->_attribute->isEmpty($changes)) {
66: $changes[$this->_attribute->getExternalName()] = $this->_default;
67: }
68: return $this->_attribute->changes($changes);
69: }
70: }