Constructs a Validator object from a Validator annotation.

@param \Mcustiel\SimpleRequest\Annotation\ValidatorAnnotation $validatorAnnotation

@return \Mcustiel\SimpleRequest\Interfaces\ValidatorInterface Created validator object.
320940
protected function createValidatorInstanceFromAnnotation($validatorAnnotation)
    {
        return ValidatorBuilder::builder()
            ->withSpecification($validatorAnnotation->getValue())
            ->withClass($validatorAnnotation->getAssociatedClass())
            ->build();
    }
923624
public function validateWith($validator, Request $request = null)
    {
        $request = $request ?: request();

        if (is_array($validator)) {
            $validator = $this->getValidationFactory()->make($request->all(), $validator);
        }

        /** @var \Illuminate\Validation\Validator $validator */
        $validator->validate();

        return $this->extractInputFromRules($request, $validator->getRules());
    }
3869
public static function fromInvalidInstantiator($instantiator) : self
    {
        return new self(sprintf(
            'Invalid instantiator given, expected `callable`, `%s` given.',
            is_object($instantiator) ? get_class($instantiator) : gettype($instantiator)
        ));
    }
871997
public function validate(ValidatorInterface $validator) {
        $validator->validate($this->getEntity());
        $messages = $validator->getMessages();
        if(is_array($messages)) {
            foreach($messages as $message) {
                $this->getEntity()->appendMessage($message);
            }
        }
    }
230027
protected function pipe(callable $validator) : ValidatorAbstract
    {
        $that = clone $this; // Immutability!
        array_push($that->restrictions, $validator);

        return $that;
    }
1291870
private static function checkValidator($validator)
    {
        if (!array_key_exists($validator, self::$validators)) {
            return self::checkClass($validator);
        }
        return self::$validators[$validator];
    }
954009
public function setValidator(Validator $validator) {
        $this->_validator = $validator;

        // Only set model events if we plan on validating
        $this->on('model', $this);

        return $this;
    }
797700
public function validateValidatorConfiguration($validatorConfiguration)
    {
        $validationErrors = array();

        foreach ($validatorConfiguration as $validatorIdentifier => $parameters) {
            switch ($validatorIdentifier) {
                case 'FileSizeValidator':
                    if (!array_key_exists('maxFileSize', $parameters)) {
                        $validationErrors[] = new ValidationError(
                            'Validator %validator% expects parameter %parameter% to be set.',
                            null,
                            array(
                                '%validator%' => $validatorIdentifier,
                                '%parameter%' => 'maxFileSize',
                            ),
                            "[$validatorIdentifier][maxFileSize]"
                        );
                        break;
                    }
                    if (!is_int($parameters['maxFileSize']) && $parameters['maxFileSize'] !== null) {
                        $validationErrors[] = new ValidationError(
                            'Validator %validator% expects parameter %parameter% to be of %type%.',
                            null,
                            array(
                                '%validator%' => $validatorIdentifier,
                                '%parameter%' => 'maxFileSize',
                                '%type%' => 'integer',
                                "[$validatorIdentifier][maxFileSize]",
                            )
                        );
                    }
                    break;
                default:
                    $validationErrors[] = new ValidationError(
                        "Validator '%validator%' is unknown",
                        null,
                        array(
                            '%validator%' => $validatorIdentifier,
                        ),
                        "[$validatorIdentifier]"
                    );
            }
        }

        return $validationErrors;
    }
414813
public function getValidator()
    {
        $validatorGenerator = new ValidatorGenerator([
            'name' => $this->name,
        ]);

        $validator = $validatorGenerator->getRootNamespace() . '\\' . $validatorGenerator->getName();

        return 'use ' . str_replace([
            "\\",
            '/'
        ], '\\', $validator) . 'Validator;';
    }
1103907
public function createValidator(string $name): ValidatorInterface
    {
        if (isset($this->validators[$name])) {
            return $this->validators[$name];
        }

        if (($validator = $this->getValidatorDefine($name)) !== false) {
            if (Assert::string($validator)) {
                if (Assert::namespace($validator)) {
                    $namespace = $validator;
                } else {
                    $namespace = '\\One\\Validation\\Validators\\' . $validator;
                }

                $this->validators[$name] = Reflection::newInstance(
                    $namespace,
                    [ $this ]
                );

                unset($namespace);
            } elseif (Assert::array($validator)) {
                $this->validators[$name] = CustomValidator::createFromArray($this, $validator);
            } else {
                $this->validators[$name] = CustomValidator::createFromClosure($this, $validator);
            }

            return $this->validators[$name];
        }

        throw new ValidationException(sprintf('Validator "%s" not found', $name));
    }
396943
public function getObjectValidator($object)
    {
        $validator = new ObjectValidator();

        $classComment = $this->annotationReader->readClass($object);
        foreach ($classComment->getAnnotations() as $class => $annotations) {
            foreach ($annotations as $annotation) {
                if ($annotation instanceof Rule) {
                    $validator->addRule($annotation);
                }
            }
        }

        $methods = $this->annotationReader->readMethods($object);
        foreach ($methods as $methodName => $comment) {
            /** @var Comment $comment */
            foreach ($comment->getAnnotations() as $class => $annotations) {
                foreach ($annotations as $annotation) {
                    if ($annotation instanceof Rule) {
                        $validator->addMethodRule($methodName, $annotation);
                    }
                }
            }
        }

        $properties = $this->annotationReader->readProperties($object);
        foreach ($properties as $propertyName => $comment) {
            /** @var Comment $comment */
            foreach ($comment->getAnnotations() as $class => $annotations) {
                foreach ($annotations as $annotation) {
                    if ($annotation instanceof Rule) {
                        $validator->addPropertyRule($propertyName, $annotation);
                    }
                }
            }
        }

        return $validator;
    }
365749
protected function _setValidator($validator)
    {
        if (!is_null($validator) && !($validator instanceof ValidatorInterface)) {
            throw $this->_createInvalidArgumentException($this->__('Invalid validator'), null, null, $validator);
        }

        $this->validator = $validator;
    }
675659
public function validator()
    {
        return Validator::make(
            $this->params, $this->rules(),
            $this->messages(), $this->attributes()
        );
    }
39694
public function addValidator(ValidatorInterface $validator)
    {
        if ($validator instanceof tao_helpers_form_validators_NotEmpty) {
            $this->addAttribute('required', true);
        }
        $this->validators[] = $validator;
    }
1260119
public function addValidator($validator)
    {
        if (!$validator instanceof ValidatorInterface) {
            if (!is_callable($validator)) {
                throw new \InvalidArgumentException('Validator should be callable or ValidatorInterface.');
            }

            $validator = new CallbackValidator($validator);
        }

        $this->validators[] = $validator;

        return $this;
    }
102369
public static function create($validator, $message = null)
    {
        $class = self::checkValidator($validator);

        /** @var ValidatorInterface $object */
        $object = new $class;
        if (!is_null($message)) {
            $object->setMessage($message);
        }
        return $object;
    }
186504
public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            if ($duplicate = File::whereChecksum($this->input('checksum'))->first()) {
                $validator->errors()->add('checksum', sprintf(
                    __('msg.already_exists'), $duplicate->url, $duplicate->title
                ));
            }
        });

        return $validator;
    }