Skip to content

Instantly share code, notes, and snippets.

@jkage
Last active December 21, 2015 21:09
Show Gist options
  • Select an option

  • Save jkage/6366394 to your computer and use it in GitHub Desktop.

Select an option

Save jkage/6366394 to your computer and use it in GitHub Desktop.
call_user_func_array returning unexpected results for regex
public function validateResponses($check)
{
$count = 0;
foreach ($check['responses'] as $response) {
$validationErrors = array();
foreach ($this->validateResponse as $field => $rules) {
foreach ($rules as $rule) {
if (is_array($rule['rule'])) {
$func = $rule['rule'][0];
$args = array_slice($rule['rule'], 1);
$args = $args[0];
} else {
$func = $rule['rule'];
$args = null;
}
if (method_exists($this, $func)) {
$valid = call_user_func_array(array($this, $func), array($response[$field], $args));
print_r($valid);
} else {
$valid = forward_static_call_array(array("VusionValidation", $func), array($response[$field], $args));
}
if (!is_bool($valid) || $valid == false) {
$validationErrors[$field][] = $rule['message'];
}
}
}
if ($validationErrors != array()) {
$this->validationErrors['responses'][$count] = $validationErrors;
}
$count++;
}
if (isset($this->validationErrors['responses'])) {
return false;
}
return true;
}
dynamic content validation function
public function validDynamicContent($check)
{
preg_match_all(VusionConst::DYNAMIC_CONTENT_MATCHER_REGEX, $check['content'], $matches, PREG_SET_ORDER);
$allowed = array("domain", "key1", "key2", "otherkey");
foreach($matches as $match) {
$match = array_intersect_key($match, array_flip($allowed));
foreach ($match as $key=>$value) {
if (!preg_match(VusionConst::DYNAMIC_CONTENT_ALLOWED_REGEX, $value)) {
return __("To be used as dynamic content, '%s' can only be composed of letter(s), digit(s) and/or space(s).", $value);
}
}
if (!preg_match(VusionConst::DYNAMIC_CONTENT_DOMAIN_REGEX, $match['domain'])) {
return __("To be used as dynamic content, '%s' can only be either 'participant' or 'contentVariable'.", $match['domain']);
}
if ($match['domain'] == 'participant') {
if (isset($match['key2'])) {
return __("To be used as dynamic concent, participant only accept one key.");
}
} else if ($match['domain'] == 'contentVariable') {
if (isset($match['otherkey'])) {
return __("To be used as dynamic concent, contentVariable only accept max two keys.");
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment