Commit b3917823 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(simpleplugin) Throw Exceptions when attributes are set to non-compatible types

At least useful for webservice

issue #5807
Showing with 34 additions and 0 deletions
+34 -0
......@@ -44,6 +44,13 @@ 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
{
}
......
......@@ -120,6 +120,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);
......
......@@ -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()));
}
}
}
/*!
......
......@@ -108,6 +108,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) {
......
......@@ -154,8 +154,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)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment