3
* Handles a color attribute.
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
15
* Handles a color attribute.
17
* Copyright 2011-2013 Horde LLC (http://www.horde.org/)
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.
24
* @package Kolab_Format
25
* @author Gunnar Wrobel <wrobel@pardus.de>
26
* @license http://www.horde.org/licenses/lgpl21 LGPL
27
* @link http://www.horde.org/libraries/Horde_Kolab_Format
29
class Horde_Kolab_Format_Xml_Type_Color
30
extends Horde_Kolab_Format_Xml_Type_String
33
* Load the value of a node.
35
* @param DOMNode $node Retrieve value for this node.
36
* @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
37
* @param array $params Additiona parameters for
38
* this parse operation.
40
* @return mixed|null The value or null if no value was found.
42
public function loadNodeValue(
44
Horde_Kolab_Format_Xml_Helper $helper,
48
$result = $helper->fetchNodeValue($node);;
49
if ($result !== null) {
50
$this->_checkColor($result, $params);
56
* Update the specified attribute.
58
* @param string $name The name of the attribute
60
* @param mixed $value The value to store.
61
* @param DOMNode $parent_node The parent node of the
64
* @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
65
* @param array $params The parameters for this
67
* @param DOMNode|NULL $old_node The previous value (or
68
* null if there is none).
70
* @return DOMNode|boolean The new/updated child node or false if this
73
* @throws Horde_Kolab_Format_Exception If converting the data to XML failed.
75
public function saveNodeValue(
79
Horde_Kolab_Format_Xml_Helper $helper,
85
$this->_checkColor($value, $params);
87
return parent::saveNodeValue(
88
$name, $value, $parent_node, $helper, $params, $old_node
93
* Test if the input seems to be a real color.
95
* @param string $color The string to check.
96
* @param array $params The parameters for this operation.
100
* @throws Horde_Kolab_Format_Exception If the input is no color.
102
private function _checkColor($color, $params)
104
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color)
105
&& !$this->isRelaxed($params)) {
106
throw new Horde_Kolab_Format_Exception(
107
sprintf('Invalid color input "%s"!', $color)