Commit acb242ef authored by Ad Schellevis's avatar Ad Schellevis

(mvc, model) add support for lists of networks/addresses in NetworkField,...

(mvc, model) add support for lists of networks/addresses in NetworkField, requirement for https://github.com/opnsense/core/issues/1226
parent f8645117
...@@ -52,6 +52,11 @@ class NetworkField extends BaseField ...@@ -52,6 +52,11 @@ class NetworkField extends BaseField
*/ */
protected $internalNetMaskRequired = false; protected $internalNetMaskRequired = false;
/**
* @var null when multiple values could be provided at once, specify the split character
*/
protected $internalFieldSeparator = null;
/** /**
* always lowercase / trim networks * always lowercase / trim networks
* @param string $value * @param string $value
...@@ -74,6 +79,15 @@ class NetworkField extends BaseField ...@@ -74,6 +79,15 @@ class NetworkField extends BaseField
} }
} }
/**
* if multiple addresses / networks maybe provided at once, set separator.
* @param $value separator
*/
public function setFieldSeparator($value)
{
$this->internalFieldSeparator = $value;
}
/** /**
* retrieve field validators for this field type * retrieve field validators for this field type
* @return array returns Text/regex validator * @return array returns Text/regex validator
...@@ -86,6 +100,7 @@ class NetworkField extends BaseField ...@@ -86,6 +100,7 @@ class NetworkField extends BaseField
// accept any as target // accept any as target
$validators[] = new NetworkValidator(array( $validators[] = new NetworkValidator(array(
'message' => $this->internalValidationMessage, 'message' => $this->internalValidationMessage,
'split' => $this->internalFieldSeparator,
'netMaskRequired' => $this->internalNetMaskRequired 'netMaskRequired' => $this->internalNetMaskRequired
)); ));
} }
......
...@@ -57,9 +57,14 @@ class NetworkValidator extends Validator implements ValidatorInterface ...@@ -57,9 +57,14 @@ class NetworkValidator extends Validator implements ValidatorInterface
public function validate(\Phalcon\Validation $validator, $attribute) public function validate(\Phalcon\Validation $validator, $attribute)
{ {
$result = true; $result = true;
$value = $validator->getValue($attribute);
$msg = $this->getOption('message'); $msg = $this->getOption('message');
$fieldSplit = $this->getOption('split', null);
if ($fieldSplit == null) {
$values = array($validator->getValue($attribute));
} else {
$values = explode($fieldSplit, $validator->getValue($attribute));
}
foreach ($values as $value) {
// parse filter options // parse filter options
$filterOpt = 0; $filterOpt = 0;
switch (strtolower($this->getOption('version'))) { switch (strtolower($this->getOption('version'))) {
...@@ -115,6 +120,7 @@ class NetworkValidator extends Validator implements ValidatorInterface ...@@ -115,6 +120,7 @@ class NetworkValidator extends Validator implements ValidatorInterface
// append validation message // append validation message
$validator->appendMessage(new Message($msg, $attribute, 'NetworkValidator')); $validator->appendMessage(new Message($msg, $attribute, 'NetworkValidator'));
} }
}
return $result; return $result;
} }
......
Markdown is supported
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