1: <?php
2: /**
3: * Handles auto-generated date attributes.
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 auto-generated date attributes.
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_AutomaticDate
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($name, &$attributes, $parent_node,
52: Horde_Kolab_Format_Xml_Helper $helper,
53: $params = array())
54: {
55: $result = parent::load($name, $attributes, $parent_node, $helper, $params);
56: if ($result !== false) {
57: return $result;
58: } else {
59: $attributes[$name] = new DateTime();
60: }
61: }
62:
63: /**
64: * Load the value of a node.
65: *
66: * @param DOMNode $node Retrieve value for this node.
67: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
68: * @param array $params Additiona parameters for
69: * this parse operation.
70: *
71: * @return mixed|null The value or null if no value was found.
72: */
73: public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper,
74: $params = array())
75: {
76: $result = $helper->fetchNodeValue($node);
77: if ($result !== null) {
78: $date = Horde_Kolab_Format_Date::readUtcDateTime($result);
79: if ($date === false && !$this->isRelaxed($params)) {
80: throw new Horde_Kolab_Format_Exception(
81: sprintf('Invalid date input "%s"!', $result)
82: );
83: }
84: return $date;
85: } else {
86: return $result;
87: }
88: }
89: }
90: