Permalink
Browse files

Merge branch 'hotfix/2673' into develop

Forward port #2673
  • Loading branch information...
2 parents 41a3c03 + 794c62e commit adf6bceaa467eacfb3a5cc6a1d68363387e03c55 @weierophinney weierophinney committed Oct 10, 2012
Showing with 37 additions and 1 deletion.
  1. +3 −0 library/Zend/InputFilter/Factory.php
  2. +34 −1 library/Zend/InputFilter/Input.php
@@ -158,6 +158,9 @@ public function createInput($inputSpecification)
$input->setRequired(!$value);
}
break;
+ case 'fallback_value':
+ $input->setFallbackValue($value);
+ break;
case 'filters':
if ($value instanceof FilterChain) {
$input->setFilterChain($value);
@@ -65,6 +65,11 @@ class Input implements InputInterface
*/
protected $value;
+ /**
+ * @var mixed
+ */
+ protected $fallbackValue;
+
public function __construct($name = null)
{
$this->name = $name;
@@ -151,6 +156,16 @@ public function setValue($value)
return $this;
}
+ /**
+ * @param mixed $value
+ * @return Input
+ */
+ public function setFallbackValue($value)
+ {
+ $this->fallbackValue = $value;
+ return $this;
+ }
+
/**
* @return boolean
*/
@@ -230,6 +245,14 @@ public function getValue()
return $filter->filter($this->value);
}
+ /**
+ * @return mixed
+ */
+ public function getFallbackValue()
+ {
+ return $this->fallbackValue;
+ }
+
/**
* @param InputInterface $input
* @return Input
@@ -260,7 +283,13 @@ public function isValid($context = null)
$this->injectNotEmptyValidator();
$validator = $this->getValidatorChain();
$value = $this->getValue();
- return $validator->isValid($value, $context);
+ $result = $validator->isValid($value, $context);
+ if (!$result && $fallbackValue = $this->getFallbackValue()) {
+ $this->setValue($fallbackValue);
+ $result = true;
+ }
+
+ return $result;
}
/**
@@ -272,6 +301,10 @@ public function getMessages()
return (array) $this->errorMessage;
}
+ if ($this->getFallbackValue()) {
+ return array();
+ }
+
$validator = $this->getValidatorChain();
return $validator->getMessages();
}

0 comments on commit adf6bce

Please sign in to comment.