Commit c2b3c674 authored by Charlie Root's avatar Charlie Root Committed by Franco Fichtner

Add NetMaskRequired option to NetworkField and NetworkValidator

(cherry picked from commit 7f3e9791)
parent de90325f
...@@ -47,6 +47,11 @@ class NetworkField extends BaseField ...@@ -47,6 +47,11 @@ class NetworkField extends BaseField
*/ */
protected $internalValidationMessage = "please specify a valid network segment or address (IPv4/IPv6) "; 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 * always lowercase / trim networks
* @param string $value * @param string $value
...@@ -56,6 +61,15 @@ class NetworkField extends BaseField ...@@ -56,6 +61,15 @@ class NetworkField extends BaseField
parent::setValue(trim(strtolower($value))); 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 * retrieve field validators for this field type
* @return array returns Text/regex validator * @return array returns Text/regex validator
...@@ -66,7 +80,10 @@ class NetworkField extends BaseField ...@@ -66,7 +80,10 @@ class NetworkField extends BaseField
if ($this->internalValue != null) { if ($this->internalValue != null) {
if ($this->internalValue != "any") { if ($this->internalValue != "any") {
// accept any as target // accept any as target
$validators[] = new NetworkValidator(array('message' => $this->internalValidationMessage)); $validators[] = new NetworkValidator(array(
'message' => $this->internalValidationMessage,
'netMaskRequired' => $this->internalNetMaskRequired
));
} }
} }
return $validators; return $validators;
......
...@@ -103,6 +103,10 @@ class NetworkValidator extends Validator implements ValidatorInterface ...@@ -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) { if (filter_var($value, FILTER_VALIDATE_IP, $filterOpt) === false) {
$result = 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