Call a class based validator extension.

@param  string  $callback
@param  array   $parameters
@return bool
490380
protected function callClassBasedExtension($callback, $parameters)
    {
        list($class, $method) = explode('@', $callback);

        $instance = $this->container->make($class);

        return call_user_func_array(array($instance, $method), $parameters);
    }
458152
public function validateFormData(WebRequest $request, Response $response, callable $callback = null)
    {
        $form = $this->searchSubmittedForm($request, $response);
        
        if ($form === null) {
            return Form::NOT_SUBMITTED;
        }
        
        // Validate the data
        $errors = $form->validateFormData($this->framework);
        
        // Execute the custom validation method
        if (is_callable($callback)) {
            $callbackErrors = call_user_func_array($callback, array($this->getFormValues()));
            
            if (is_array($callbackErrors)) {
                $errors = array_merge($errors, $callbackErrors);
            }
        }
        
        if (is_array($errors) && count($errors) > 0) {
            $this->updateErrorBox($form, $errors);
            return Form::DATA_INVALID;
        }
        
        return Form::DATA_VALID;
    }
427934
public function AssignCallback($Callback, $Options = NULL) {
      if (!is_callable($Callback)) return FALSE;
      
      $this->Callback = $Callback;
      $this->CallbackOptions = $Options;
   }
413191
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(!$exists) {
            return true;
        }
        
        if(!\is_callable($value)) {
            return 'formvalidator_make_callable';
        }
        
        if(empty($options)) {
            throw new \LogicException('Invalid options value given for callback rule');
        }
        
        /** @var \ReflectionMethod|\ReflectionFunction  $prototype */
        
        if(\is_array($value)) {
            $prototype = new \ReflectionMethod($value[0], $value[1]);
        } else {
            $prototype = new \ReflectionFunction($value);
        }
        
        $options = \explode('=', $options, 2);
        
        if(!empty($options[0])) {
            $params = \explode(',', $options[0]);
            
            /** @var \ReflectionParameter  $param */
            foreach($prototype->getParameters() as $pos => $param) {
                $type = $param->getType();
                
                if(!isset($params[$pos])) {
                    return array('formvalidator_make_callback_param_superfluos', array('{0}' => $pos));
                } elseif($params[$pos] === '') {
                    continue; // "mixed" type - wildcard
                } elseif(($type === null && $params[$pos] !== '') || \trim($params[$pos], '?') !== $type->getName()) {
                    return array('formvalidator_make_callback_param', array('{0}' => $pos, '{1}' => \trim($params[$pos], '?')));
                } elseif($params[$pos][0] === '?' && !$type->allowsNull()) {
                    return array('formvalidator_make_callback_param_nullable', array('{0}' => $pos));
                } elseif(\substr($params[$pos], -1) === '?' && !$param->isOptional()) {
                    return array('formvalidator_make_callback_param_optional', array('{0}' => $pos));
                }
            }
        }
        
        if(!empty($options[1])) {
            $return = $prototype->getReturnType();
            
            if($return === null) {
                return array('formvalidator_make_callback_return', array('{0}' => $options[1]));
            } elseif(($return->allowsNull() ? '?' : '').$return->getName() !== $options[1]) {
                return array('formvalidator_make_callback_return_type', array('{0}' => $options[1], '{1}' => $return->getName()));
            }
        }
        
        return true;
    }
1227192
public function validate(array $parameters = array()) {
        $validated= false;
        $this->reset();
        $stopOnFail= isset($parameters['stopOnFail']) && $parameters['stopOnFail']
                ? true
                : false;
        $stopOnRuleFail= isset($parameters['stopOnRuleFail']) && $parameters['stopOnRuleFail']
                ? true
                : false;
        if (!empty($this->object->_validationRules)) {
            foreach ($this->object->_validationRules as $column => $rules) {
                $this->results[$column]= $this->object->isValidated($column);
                if (!$this->results[$column]) {
                    $columnResults= array();
                    foreach ($rules as $ruleName => $rule) {
                        $result= false;
                        if (is_array($rule['parameters'])) $rule['parameters']['column'] = $column;
                        switch ($rule['type']) {
                            case 'callable':
                                $callable= $rule['rule'];
                                if (is_callable($callable)) {
                                     $result= call_user_func_array($callable, array($this->object->_fields[$column],$rule['parameters']));
                                    if (!$result) $this->addMessage($column, $ruleName, isset($rule['parameters']['message']) ? $rule['parameters']['message'] : $ruleName . ' failed');
                                } else {
                                    $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Validation function {$callable} is not a valid callable function.");
                                }
                                break;
                            case 'preg_match':
                                $result= (boolean) preg_match($rule['rule'], $this->object->_fields[$column]);
                                if (!$result) $this->addMessage($column, $ruleName, isset($rule['parameters']['message']) ? $rule['parameters']['message'] : $ruleName . ' failed');
                                if ($this->object->xpdo->getDebug() === true)
                                    $this->object->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "preg_match validation against {$rule['rule']} resulted in " . print_r($result, 1));
                                break;
                            case 'xPDOValidationRule':
                                if ($ruleClass= $rule['rule']) {
                                    if (strpos($ruleClass, '\\') === false && strpos($ruleClass, '.') === false) {
                                        $ruleClass = __NAMESPACE__ . '\\' . $ruleClass;
                                    }
                                    if ($ruleObject= new $ruleClass($this, $column, $ruleName)) {
                                        $callable= array($ruleObject, 'isValid');
                                        if (is_callable($callable)) {
                                            $callableParams= array($this->object->_fields[$column], $rule['parameters']);
                                            $result= call_user_func_array($callable, $callableParams);
                                        } else {
                                            $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Validation rule class {$rule['rule']} does not have an isValid() method.");
                                        }
                                    }
                                } else {
                                    $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not load validation rule class: {$rule['rule']}");
                                }
                                break;
                            default:
                                $this->object->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Unsupported validation rule: " . print_r($rule, true));
                                break;
                        }
                        $columnResults[$ruleName]= $result;
                        if (!$result && $stopOnRuleFail) {
                            break;
                        }
                    }
                    $this->results[$column]= !in_array(false, $columnResults, true) ? true : false;
                    if (!$this->results[$column] && $stopOnFail) {
                        break;
                    }
                }
                if ($this->results[$column]) {
                    $this->object->_validated[$column]= $column;
                }
            }
            if (empty($this->results) || !in_array(false, $this->results, true)) {
                $validated = true;
                if ($this->object->xpdo->getDebug() === true)
                    $this->object->xpdo->log(xPDO::LOG_LEVEL_WARN, "Validation succeeded: " . print_r($this->results, true));
            } elseif ($this->object->xpdo->getDebug() === true) {
                $this->object->xpdo->log(xPDO::LOG_LEVEL_WARN, "Validation failed: " . print_r($this->results, true));
            }
        } else {
            if ($this->object->xpdo->getDebug() === true) $this->object->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Validation called but no rules were found.");
            $validated = true;
        }
        return $validated;
    }
503934
protected function getCallback($callback, array $parameters)
    {
        if ($callback instanceof Closure) {
            return $this->createCallableCallback($callback, $parameters);
        } elseif (is_string($callback)) {
            return $this->createStringCallback($callback, $parameters);
        } else {
            return;
        }
    }
1120039
public static function extend($method, $callback = null)
    {
        if (is_array($method)) {
            foreach ($method as $key => $val) {
                self::$extend[strtolower($key)] = $val;
            }
        } else {
            self::$extend[strtolower($method)] = $callback;
        }
    }
244129
protected function handleCallback($callback, array $args = [])
    {
        $response = null;

        // Check if $callback is a closure.
        if ($callback instanceof \Closure || is_array($callback)) {
            $response = call_user_func($callback, $args);
        } elseif (is_string($callback)) {
            if (false !== strpos($callback, '@') || class_exists($callback)) {
                // We use a "ClassName@method" syntax.
                // Let's get a class instance and call its method.
                $callbackArray = $this->handleClassCallback($callback);
                $response = call_user_func($callbackArray, $args);
            } else {
                // Used as a classic callback function.
                $response = call_user_func($callback, $args);
            }
        }

        return $response;
    }
72056
protected function callbackAllowsGuests($callback)
    {
        $parameters = (new ReflectionFunction($callback))->getParameters();

        return isset($parameters[0]) && $this->parameterAllowsGuests($parameters[0]);
    }
1323381
public function call($callback, $params = [], $fallback = null)
    {
        return $this->circuitState->doCall($callback, $params, $fallback);
    }
138512
protected function callback($callback, array $args = [])
    {
        if (isset($callback)) {
            if (is_callable($callback) && $callback instanceof \Closure) {
                // Set new object and append the callback with some data.
                $o = new \ArrayObject($args);
                $o->app = App::instance();
                $callback = $callback->bindTo($o);
            } elseif (is_string($callback) && strpos($callback, '@') !== false) {
                $fixcallback = explode('@', $callback, 2);
                $this->Controller = $fixcallback[0];

                if (is_callable(
                    $callback = [$fixcallback[0], (isset($fixcallback[1]) ? $fixcallback[1] : 'index')]
                )) {
                    $this->Method = $callback[1];
                } else {
                    throw new \Exception("Callable error on {$callback[0]} -> {$callback[1]} !");
                }
            }

            if (is_array($callback) && !is_object($callback[0])) {
                $callback[0] = new $callback[0];
            }

            if (isset($args[0]) && $args[0] == $this->fullArg) {
                array_shift($args);
            }

            // Finally, call the method.
            return call_user_func_array($callback, $args);
        }
        return false;
    }
731015
static function executeCallback($callback, array $params = array()) {
    // If callback has @
    if (is_string($callback) && strpos($callback, '@') !== false) {
      // Split
      $arrCallback = explode('@', $callback);
      // Set object
      $object = class_exists($arrCallback[0]) ? (new $arrCallback[0]()) : null;
      // Set method
      $method = isset($arrCallback[0]) ? $arrCallback[0] : null;
      // Set callback
      $callback = array($object, $method);
    }
    // If not callable
    if ( ! is_callable($callback)) {
      // Throw error
      throw new InvalidCallback('Callback must be callable');
    }
    // Execute and return
    return call_user_func_array($callback, $params);
  }
229490
public function call($callback, array $parameters = [])
    {
        $this->_events[] = $event = new CallbackEvent($callback, $parameters);

        return $event;
    }
1369834
protected function callMessageBuilder($callback, $message)
    {
        if ($callback instanceof Closure) {
            return call_user_func($callback, $message);
        } else if (is_string($callback)) {
            return $this->container[$callback]->mail($message);
        }

        throw new \InvalidArgumentException("Callback is not valid.");
    }
1013516
protected function callClassBasedExtension($callback, $parameters)
    {
        list($class, $method) = explode('@', $callback);

        return call_user_func_array([$class, $method], $parameters);
    }
1353708
public function call($callback, array $parameters = array(), $defaultMethod = null)
    {
        if ($this->isCallableWithAtSign($callback) || $defaultMethod) {
            return $this->callClass($callback, $parameters, $defaultMethod);
        }

        $dependencies = $this->getMethodDependencies($callback, $parameters);

        return call_user_func_array($callback, $dependencies);
    }
122020
private function run($callback)
    {
        $injects = [];
        $reflectionFunction = new \ReflectionFunction($callback);
        foreach ($reflectionFunction->getParameters() as $parameter) {
            if ($class = $parameter->getClass()) {
                $injects[] = app($class->name);
            }
        }

        return call_user_func_array($callback, $injects);
    }