mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
Remove legacy dependence on create_function() from Validator class #1480
This commit is contained in:
parent
372e392049
commit
485b22ea22
1 changed files with 28 additions and 7 deletions
|
|
@ -341,10 +341,8 @@ class Validator
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$func_body = preg_replace('/\\$(\w+)/', '$c[\'$1\']', $cond['test']);
|
$expr = '!!(' . preg_replace('/\\$(\w+)/', '$value[\'$1\']', $cond['test']) . ')';
|
||||||
$func = create_function('$c', "return !!({$func_body});");
|
if(self::_execExpression($fields, $expr))
|
||||||
|
|
||||||
if($func($fields))
|
|
||||||
{
|
{
|
||||||
$filter[$cond['attr']] = $cond['value'];
|
$filter[$cond['attr']] = $cond['value'];
|
||||||
}
|
}
|
||||||
|
|
@ -621,12 +619,16 @@ class Validator
|
||||||
case 'enum':
|
case 'enum':
|
||||||
return in_array($value, $rule['test']);
|
return in_array($value, $rule['test']);
|
||||||
case 'expr':
|
case 'expr':
|
||||||
if(!$rule['func_test'])
|
if(is_callable($rule['func_test']))
|
||||||
{
|
{
|
||||||
$rule['func_test'] = create_function('$a', 'return (' . preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])) . ');');
|
|
||||||
}
|
|
||||||
return $rule['func_test']($value);
|
return $rule['func_test']($value);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$expr = '(' . preg_replace('/\$\$/', '$value', html_entity_decode($rule['test'])) . ')';
|
||||||
|
return self::_execExpression($value, $expr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
@ -830,6 +832,25 @@ class Validator
|
||||||
return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\n{$addrules}\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);\n{$messages}\n})(jQuery);";
|
return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\n{$addrules}\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);\n{$messages}\n})(jQuery);";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polyfill for create_function()
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string $expression
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected static function _execExpression($value, $expression)
|
||||||
|
{
|
||||||
|
$hash_key = sha1($expression);
|
||||||
|
$filename = RX_BASEDIR . 'files/cache/validator/' . $hash_key . '.php';
|
||||||
|
if (!Rhymix\Framework\Storage::exists($filename))
|
||||||
|
{
|
||||||
|
$buff = '<?php if(!defined(\'RX_VERSION\')) return;' . "\n" . 'return ' . $expression . ';' . "\n";
|
||||||
|
Rhymix\Framework\Storage::write($filename, $buff);
|
||||||
|
}
|
||||||
|
return (include $filename);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/* End of file Validator.class.php */
|
/* End of file Validator.class.php */
|
||||||
/* Location: ./classes/validator/Validator.class.php */
|
/* Location: ./classes/validator/Validator.class.php */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue