1
0
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:
Ryan Cramer
2019-01-25 11:58:26 -05:00
parent e879baf189
commit 1aad2430d5
2 changed files with 20 additions and 16 deletions

View File

@@ -989,7 +989,8 @@ class WireInput extends Wire {
/** @var Sanitizer $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);
$cleanValues = array();
@@ -997,10 +998,8 @@ class WireInput extends Wire {
foreach($methods as $method) {
$method = trim($method);
if(empty($method)) continue;
if(method_exists($sanitizer, $method)) {
$value = call_user_func_array(array($sanitizer, $method), array($value));
} else if(method_exists($sanitizer, "___$method")) {
$value = call_user_func_array(array($sanitizer, "___$method"), array($value));
if($sanitizer->methodExists($method)) {
$value = $sanitizer->sanitize($value, $method);
} else {
throw new WireException("Unknown sanitizer method: $method");
}

View File

@@ -285,25 +285,30 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C
* @throws WireException
*
*/
public function __call($method, $arguments) {
public function ___callUnknown($method, $arguments) {
$sanitizer = $this->wire('sanitizer');
$method = ltrim($method, '_');
if(!method_exists($sanitizer, $method)) {
$method = "___$method";
if(!method_exists($sanitizer, $method)) {
$method = ltrim($method, "_");
throw new WireException("Unknown method '$method' - Specify a valid Sanitizer or WireInputData method.");
if(!$sanitizer->methodExists($method)) {
try {
return parent::___callUnknown($method, $arguments);
} catch(\Exception $e) {
throw new WireException("Unknown method '$method' - specify a valid Sanitizer name or WireInputData method");
}
}
if(!isset($arguments[0])) {
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]);
if(is_null($arguments[0])) {
// value is not present in input at all
// @todo do you want to provide an alternate means of handling this situation?
if($arguments[0] === null) {
// value is not present in input at all, accommodate potential fallback value?
}
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);
}
}