diff --git a/include/class_exceptions.inc b/include/class_exceptions.inc index 7bbb356c97a03335f76135722e8784be71524e8b..a5553ceec81bf28d0ed0630e680887c1f72e6281 100644 --- a/include/class_exceptions.inc +++ b/include/class_exceptions.inc @@ -38,6 +38,13 @@ class LDIFImportException extends FusionDirectoryException {} */ class LdapGeneralizedTimeBadFormatException extends FusionDirectoryException {} +/*! \class InvalidValueException + \brief Exception class which can be thrown if an attribute is set to a value with a non-compatible type +*/ +class InvalidValueException extends FusionDirectoryException +{ +} + class NonExistingObjectTypeException extends FusionDirectoryException {} class NonExistingBranchException extends FusionDirectoryException {} class NonExistingLdapNodeException extends FusionDirectoryException {} diff --git a/include/simpleplugin/attributes/class_BaseSelectorAttribute.inc b/include/simpleplugin/attributes/class_BaseSelectorAttribute.inc index 4c4351a5bc649045565eb4f308786cbc79105983..e60e4c3c80183632a3aaa819d3a67765263b74ae 100644 --- a/include/simpleplugin/attributes/class_BaseSelectorAttribute.inc +++ b/include/simpleplugin/attributes/class_BaseSelectorAttribute.inc @@ -118,6 +118,13 @@ class BaseSelectorAttribute extends Attribute } } + function checkValue($value) + { + if (!is_string($value) && (!is_object($value) || !method_exists($value, '__toString' ))) { + throw new InvalidValueException(_('Base field value should always be a string')); + } + } + function setValue ($value) { parent::setValue($value); diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc index 53679615ddd99e59d72590e7537bc5ee552f5898..fa092e42bc2151021f6dc3af8a6e244a133efbea 100644 --- a/include/simpleplugin/attributes/class_SetAttribute.inc +++ b/include/simpleplugin/attributes/class_SetAttribute.inc @@ -339,6 +339,13 @@ class SetAttribute extends Attribute { $this->size = $size; } + + function checkValue($value) + { + if (!is_array($value)) { + throw new InvalidValueException(sprintf(_('SetAttribute "%s" was set to a non-compatible value'), $this->getLabel())); + } + } } class OrderedArrayAttribute extends SetAttribute diff --git a/include/simpleplugin/attributes/class_StringAttribute.inc b/include/simpleplugin/attributes/class_StringAttribute.inc index c9a7ab8c151129f4f4f5a993a730c8353627cea5..5fe3d3f3ccd269a71635d7625c4862c1faa6c53a 100644 --- a/include/simpleplugin/attributes/class_StringAttribute.inc +++ b/include/simpleplugin/attributes/class_StringAttribute.inc @@ -107,6 +107,13 @@ class StringAttribute extends Attribute return $this->autocomplete; } + function checkValue($value) + { + if (!is_scalar($value) && (!is_object($value) || !method_exists($value, '__toString' ))) { + throw new InvalidValueException(sprintf(_('StringAttribute "%s" was set to a non-compatible value'), $this->getLabel())); + } + } + function setValue ($value) { if ($this->trim) { diff --git a/include/simpleplugin/class_Attribute.inc b/include/simpleplugin/class_Attribute.inc index 283b8601163f17a87745ad58f1f1e74ad0ce9376..8228f7e3028988ff9c3e511dda9cfa747e092c8e 100644 --- a/include/simpleplugin/class_Attribute.inc +++ b/include/simpleplugin/class_Attribute.inc @@ -149,8 +149,14 @@ class Attribute return $this->inLdap; } + function checkValue ($value) + { + /* Should throw InvalidValueException if needed */ + } + function setValue ($value) { + $this->checkValue($value); $old_value = $this->value; $this->value = $value; if (($this->submitForm != FALSE) && ($this->submitForm !== TRUE) && ($old_value != $value) && is_object($this->plugin)) {