Dont set null values when validating storage definition
This commit is contained in:
parent
efcf790eff
commit
d0f5687687
3 changed files with 12 additions and 6 deletions
|
@ -154,6 +154,10 @@ class DefinitionParameter implements \JsonSerializable {
|
||||||
return $prefix . $this->getText();
|
return $prefix . $this->getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isOptional() {
|
||||||
|
return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a parameter value against this
|
* Validate a parameter value against this
|
||||||
* Convert type as necessary
|
* Convert type as necessary
|
||||||
|
@ -162,8 +166,6 @@ class DefinitionParameter implements \JsonSerializable {
|
||||||
* @return bool success
|
* @return bool success
|
||||||
*/
|
*/
|
||||||
public function validateValue(&$value) {
|
public function validateValue(&$value) {
|
||||||
$optional = $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
|
|
||||||
|
|
||||||
switch ($this->getType()) {
|
switch ($this->getType()) {
|
||||||
case self::VALUE_BOOLEAN:
|
case self::VALUE_BOOLEAN:
|
||||||
if (!is_bool($value)) {
|
if (!is_bool($value)) {
|
||||||
|
@ -180,7 +182,7 @@ class DefinitionParameter implements \JsonSerializable {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!$value && !$optional) {
|
if (!$value && !$this->isOptional()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -136,10 +136,12 @@ trait FrontendDefinitionTrait {
|
||||||
public function validateStorageDefinition(StorageConfig $storage) {
|
public function validateStorageDefinition(StorageConfig $storage) {
|
||||||
foreach ($this->getParameters() as $name => $parameter) {
|
foreach ($this->getParameters() as $name => $parameter) {
|
||||||
$value = $storage->getBackendOption($name);
|
$value = $storage->getBackendOption($name);
|
||||||
if (!$parameter->validateValue($value)) {
|
if (!is_null($value) || !$parameter->isOptional()) {
|
||||||
return false;
|
if (!$parameter->validateValue($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$storage->setBackendOption($name, $value);
|
||||||
}
|
}
|
||||||
$storage->setBackendOption($name, $value);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,8 @@ class FrontendDefinitionTraitTest extends \Test\TestCase {
|
||||||
->getMock();
|
->getMock();
|
||||||
$param->method('getName')
|
$param->method('getName')
|
||||||
->willReturn($name);
|
->willReturn($name);
|
||||||
|
$param->method('isOptional')
|
||||||
|
->willReturn(false);
|
||||||
$param->expects($this->once())
|
$param->expects($this->once())
|
||||||
->method('validateValue')
|
->method('validateValue')
|
||||||
->willReturn($valid);
|
->willReturn($valid);
|
||||||
|
|
Loading…
Reference in a new issue