1: <?php
2: /**
3: * Handles the UID attribute.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Format
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL
11: * @link http://www.horde.org/libraries/Horde_Kolab_Format
12: */
13:
14: /**
15: * Handles the UID attribute.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you did not
20: * receive this file, see
21: * http://www.horde.org/licenses/lgpl21.
22: *
23: * @since Horde_Kolab_Format 1.1.0
24: *
25: * @category Kolab
26: * @package Kolab_Format
27: * @author Gunnar Wrobel <wrobel@pardus.de>
28: * @license http://www.horde.org/licenses/lgpl21 LGPL
29: * @link http://www.horde.org/libraries/Horde_Kolab_Format
30: */
31: class Horde_Kolab_Format_Xml_Type_Uid
32: extends Horde_Kolab_Format_Xml_Type_Base
33: {
34: /**
35: * Load the node value from the Kolab object.
36: *
37: * @param string $name The name of the the
38: * attribute to be fetched.
39: * @param array &$attributes The data array that
40: * holds all attribute
41: * values.
42: * @param DOMNode $parent_node The parent node of the
43: * node to be loaded.
44: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
45: * @param array $params Additiona parameters for
46: * this parse operation.
47: *
48: * @return DOMNode|boolean The named DOMNode or false if no node value was
49: * found.
50: */
51: public function load(
52: $name,
53: &$attributes,
54: $parent_node,
55: Horde_Kolab_Format_Xml_Helper $helper,
56: $params = array()
57: )
58: {
59: $result = parent::load($name, $attributes, $parent_node, $helper, $params);
60: if (!$result && !$this->isRelaxed($params)) {
61: throw new Horde_Kolab_Format_Exception_MissingUid();
62: }
63: return $result;
64: }
65:
66: /**
67: * Update the specified attribute.
68: *
69: * @param string $name The name of the the
70: * attribute to be updated.
71: * @param array $attributes The data array that holds
72: * all attribute values.
73: * @param DOMNode $parent_node The parent node of the
74: * node that should be
75: * updated.
76: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
77: * @param array $params Additional parameters
78: * for this write operation.
79: *
80: * @return DOMNode|boolean The new/updated child node or false if this
81: * failed.
82: *
83: * @throws Horde_Kolab_Format_Exception If converting the data to XML failed.
84: */
85: public function save(
86: $name,
87: $attributes,
88: $parent_node,
89: Horde_Kolab_Format_Xml_Helper $helper,
90: $params = array()
91: )
92: {
93: $node = $helper->findNodeRelativeTo(
94: './' . $name, $parent_node
95: );
96:
97: if ($node === false) {
98: if (!isset($attributes[$name])) {
99: if ($this->isRelaxed($params)) {
100: return false;
101: } else {
102: throw new Horde_Kolab_Format_Exception_MissingUid();
103: }
104: }
105: } else {
106: if (isset($attributes[$name])) {
107: if (($old = $this->loadNodeValue($node, $helper, $params)) != $attributes[$name]) {
108: if (!$this->isRelaxed($params)) {
109: throw new Horde_Kolab_Format_Exception(
110: sprintf(
111: 'Not attempting to overwrite old %s %s with new value %s!',
112: $name,
113: $old,
114: $attributes['uid']
115: )
116: );
117: }
118: } else {
119: return $node;
120: }
121: }
122: }
123:
124: $result = $this->saveNodeValue(
125: $name,
126: $this->generateWriteValue($name, $attributes, $params),
127: $parent_node,
128: $helper,
129: $params,
130: $node
131: );
132: return ($node !== false) ? $node : $result;
133: }
134: }
135: