Skip to content

Commit a5977a9

Browse files
authored
Update Valigator.php
1 parent f54fab3 commit a5977a9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Valigator.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Valigator
3838
'bool' => 'boolean',
3939
'casttonum' => 'casttonumeric',
4040
'casttonumber' => 'casttonumeric',
41+
'defaultphp' => 'defaultspecial',
4142
'encode_amp' => FILTER_FLAG_ENCODE_AMP,
4243
'encode_high' => FILTER_FLAG_ENCODE_HIGH,
4344
'encode_low' => FILTER_FLAG_ENCODE_LOW,
@@ -1269,7 +1270,7 @@ public function runSanitizations($input)
12691270
}
12701271
}
12711272

1272-
if ($filterSynonym == 'default') {
1273+
if (in_array($filterSynonym, ['default', 'defaultspecial'])) {
12731274
$method = "sanitize_{$filterSynonym}";
12741275
$fieldValue = &$this->_getFieldValueFromInput($field, $input, TRUE);
12751276
$fieldValue = $this->$method($fieldValue, $argsSynonyms);
@@ -1459,6 +1460,24 @@ protected function sanitize_default($value, $args = NULL)
14591460
return ($value === NULL || $value === '' || $value === array()) ? $args[0] : $value;
14601461
}
14611462

1463+
protected function sanitize_defaultspecial($value, $args = NULL)
1464+
{
1465+
if ($value === NULL || $value === '' || $value === array()) {
1466+
switch (strtolower($args[0])) {
1467+
case 'null':
1468+
$value = NULL;
1469+
break;
1470+
case 'array()':
1471+
case '[]':
1472+
$value = array();
1473+
break;
1474+
default:
1475+
$value = $args[0];
1476+
}
1477+
}
1478+
return $value;
1479+
}
1480+
14621481
/**
14631482
* Sanitize the string by removing illegal characters from emails.
14641483
*

0 commit comments

Comments
 (0)