mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Update WireInput/WireInputData to optimize for sanitizer updates
This commit is contained in:
@@ -989,7 +989,8 @@ class WireInput extends Wire {
|
|||||||
|
|
||||||
/** @var Sanitizer $sanitizer */
|
/** @var Sanitizer $sanitizer */
|
||||||
$sanitizer = $this->wire('sanitizer');
|
$sanitizer = $this->wire('sanitizer');
|
||||||
$values = is_array($value) ? $value : ($value === null ? array() : array($value));
|
//$values = is_array($value) ? $value : ($value === null ? array() : array($value));
|
||||||
|
$values = is_array($value) ? $value : array($value);
|
||||||
$methods = strpos($method, ',') === false ? array($method) : explode(',', $method);
|
$methods = strpos($method, ',') === false ? array($method) : explode(',', $method);
|
||||||
$cleanValues = array();
|
$cleanValues = array();
|
||||||
|
|
||||||
@@ -997,10 +998,8 @@ class WireInput extends Wire {
|
|||||||
foreach($methods as $method) {
|
foreach($methods as $method) {
|
||||||
$method = trim($method);
|
$method = trim($method);
|
||||||
if(empty($method)) continue;
|
if(empty($method)) continue;
|
||||||
if(method_exists($sanitizer, $method)) {
|
if($sanitizer->methodExists($method)) {
|
||||||
$value = call_user_func_array(array($sanitizer, $method), array($value));
|
$value = $sanitizer->sanitize($value, $method);
|
||||||
} else if(method_exists($sanitizer, "___$method")) {
|
|
||||||
$value = call_user_func_array(array($sanitizer, "___$method"), array($value));
|
|
||||||
} else {
|
} else {
|
||||||
throw new WireException("Unknown sanitizer method: $method");
|
throw new WireException("Unknown sanitizer method: $method");
|
||||||
}
|
}
|
||||||
|
@@ -285,25 +285,30 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C
|
|||||||
* @throws WireException
|
* @throws WireException
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __call($method, $arguments) {
|
public function ___callUnknown($method, $arguments) {
|
||||||
$sanitizer = $this->wire('sanitizer');
|
$sanitizer = $this->wire('sanitizer');
|
||||||
$method = ltrim($method, '_');
|
if(!$sanitizer->methodExists($method)) {
|
||||||
if(!method_exists($sanitizer, $method)) {
|
try {
|
||||||
$method = "___$method";
|
return parent::___callUnknown($method, $arguments);
|
||||||
if(!method_exists($sanitizer, $method)) {
|
} catch(\Exception $e) {
|
||||||
$method = ltrim($method, "_");
|
throw new WireException("Unknown method '$method' - specify a valid Sanitizer name or WireInputData method");
|
||||||
throw new WireException("Unknown method '$method' - Specify a valid Sanitizer or WireInputData method.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!isset($arguments[0])) {
|
if(!isset($arguments[0])) {
|
||||||
throw new WireException("For method '$method' specify an input variable name for first argument");
|
throw new WireException("For method '$method' specify an input variable name for first argument");
|
||||||
}
|
}
|
||||||
|
// swap input name with input value in arguments array
|
||||||
$arguments[0] = $this->__get($arguments[0]);
|
$arguments[0] = $this->__get($arguments[0]);
|
||||||
if(is_null($arguments[0])) {
|
if($arguments[0] === null) {
|
||||||
// value is not present in input at all
|
// value is not present in input at all, accommodate potential fallback value?
|
||||||
// @todo do you want to provide an alternate means of handling this situation?
|
}
|
||||||
|
if(count($arguments) > 1) {
|
||||||
|
// more than one argument to sanitizer method
|
||||||
|
return call_user_func_array(array($sanitizer, $method), $arguments);
|
||||||
|
} else {
|
||||||
|
// single argument, pass along to sanitize method
|
||||||
|
return $sanitizer->sanitize($arguments[0], $method);
|
||||||
}
|
}
|
||||||
return call_user_func_array(array($sanitizer, $method), $arguments);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user