Commit 036e661c authored by Ad Schellevis's avatar Ad Schellevis

Merge pull request #789 from evbevz/network-field-netmaskrequired-validator

Add NetMaskRequired option into NetworkField and NetworkValidator
parents df7e8660 7f3e9791
......@@ -47,6 +47,11 @@ class NetworkField extends BaseField
*/
protected $internalValidationMessage = "please specify a valid network segment or address (IPv4/IPv6) ";
/**
* @var bool marks if net mask is required
*/
protected $internalNetMaskRequired = false;
/**
* always lowercase / trim networks
* @param string $value
......@@ -56,6 +61,15 @@ class NetworkField extends BaseField
parent::setValue(trim(strtolower($value)));
}
/**
* setter for net mask required
* @param integer $value
*/
public function setNetMaskRequired($value)
{
$this->internalNetMaskRequired = (trim(strtolower($value)) == 'y' || intval($value) == 1);
}
/**
* retrieve field validators for this field type
* @return array returns Text/regex validator
......@@ -66,7 +80,10 @@ class NetworkField extends BaseField
if ($this->internalValue != null) {
if ($this->internalValue != "any") {
// accept any as target
$validators[] = new NetworkValidator(array('message' => $this->internalValidationMessage));
$validators[] = new NetworkValidator(array(
'message' => $this->internalValidationMessage,
'netMaskRequired' => $this->internalNetMaskRequired
));
}
}
return $validators;
......
......@@ -103,6 +103,10 @@ class NetworkValidator extends Validator implements ValidatorInterface
}
}
}
else if($this->getOption('netMaskRequired') === true) {
$result = false;
}
if (filter_var($value, FILTER_VALIDATE_IP, $filterOpt) === false) {
$result = false;
......
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