Create a validator for the element

@param string $validatorIdentifier
@param array $options
@return mixed
@throws ValidatorPresetNotFoundException
330144
public function createValidator($validatorIdentifier, array $options = [])
    {
        $validatorPresets = $this->getRootForm()->getValidatorPresets();
        if (isset($validatorPresets[$validatorIdentifier]) && is_array($validatorPresets[$validatorIdentifier]) && isset($validatorPresets[$validatorIdentifier]['implementationClassName'])) {
            $implementationClassName = $validatorPresets[$validatorIdentifier]['implementationClassName'];
            $defaultOptions = isset($validatorPresets[$validatorIdentifier]['options']) ? $validatorPresets[$validatorIdentifier]['options'] : [];

            $options = Arrays::arrayMergeRecursiveOverrule($defaultOptions, $options);

            $validator = new $implementationClassName($options);
            $this->addValidator($validator);
            return $validator;
        } else {
            throw new ValidatorPresetNotFoundException('The validator preset identified by "' . $validatorIdentifier . '" could not be found, or the implementationClassName was not specified.', 1328710202);
        }
    }
933762
public function addValidation($property, $validation, $options = array())
    {
        $validations = $this->getValidations($property);
        $validations[$validation] = $options;

        return $this;
    }
1232397
public function setOptionValidator(\JBBCode\InputValidator $validator, $option=null)
    {
        if (empty($option)) {
            $option = $this->tagName;
        }
        $this->optionValidator[$option] = $validator;
        return $this;
    }
427933
public function setValidationRules($table, string $field, Validator $validator, array $options = []) : Validator
    {
        $handler = self::getByTableField($table, $field);
        $validator = $handler->setValidationRules($validator, $options);
        if (! $validator instanceof Validator) {
            throw new RuntimeException(
                sprintf('Field Handler returned value must be an instance of %s.', Validator::class)
            );
        }

        return $validator;
    }
721552
public function validationEnabled(Validator $validator) : Validator
    {
        $className = App::shortName(get_class($this), 'Model/Table', 'Table');
        $config = (new ModuleConfig(ConfigType::MIGRATION(), $className))->parse();
        $config = json_encode($config);
        if (false === $config) {
            return $validator;
        }
        $config = json_decode($config, true);
        $factory = new FieldHandlerFactory();

        foreach ($config as $column) {
            $validator = $factory->setValidationRules($this, $column['name'], $validator);
        }

        return $validator;
    }
1340806
public function addValidator(Validator\ValidatorInterface $validator) {
        $this->validators[get_class($validator)] = $validator;
        
        return $this;
    }
1347168
protected function useValidator(Validator $validator)
    {
        if (substr($this->account, 2, 2) == '99') {
            return $validator === $this->validators[2]
                || $validator === $this->validators[3];

        } else {
            return  $validator !== $this->validators[2];

        }
    }
954009
public function setValidator(Validator $validator) {
        $this->_validator = $validator;

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

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

        foreach ($validatorConfiguration as $validatorIdentifier => $constraints) {
            if ($validatorIdentifier !== 'FloatValueValidator') {
                $validationErrors[] = new ValidationError(
                    "Validator '%validator%' is unknown",
                    null,
                    array(
                        '%validator%' => $validatorIdentifier,
                    ),
                    "[$validatorIdentifier]"
                );

                continue;
            }

            foreach ($constraints as $name => $value) {
                switch ($name) {
                    case 'minFloatValue':
                    case 'maxFloatValue':
                        if ($value !== null && !is_numeric($value)) {
                            $validationErrors[] = new ValidationError(
                                "Validator parameter '%parameter%' value must be of numeric type",
                                null,
                                array(
                                    '%parameter%' => $name,
                                ),
                                "[$validatorIdentifier][$name]"
                            );
                        }
                        break;
                    default:
                        $validationErrors[] = new ValidationError(
                            "Validator parameter '%parameter%' is unknown",
                            null,
                            array(
                                '%parameter%' => $name,
                            ),
                            "[$validatorIdentifier][$name]"
                        );
                }
            }
        }

        return $validationErrors;
    }
1341975
public function validate(array $options = array()) {
        $validated= false;
        if ($validator= $this->getValidator()) {
            $validated= $this->_validator->validate($options);
            if ($this->xpdo->getDebug() === true) {
                $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Validator class executed, result = " . print_r($validated, true));
            }
        } else {
            if ($this->xpdo->getDebug() === true) {
                $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "No validator found for {$this->_class} instance.");
            }
            $validated= true;
        }
        return $validated;
    }
596813
public function validationDefault(Validator $validator) {
		$validator
			->integer('id')
			->allowEmpty('id', 'create');

		$validator
			->requirePresence('address', 'create')
			->notEmpty('address')
			->add('address', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);

		$validator
			->allowEmpty('formatted_address');

		$validator
			->allowEmpty('country');

		$validator
			->decimal('lat')
			->allowEmpty('lat');

		$validator
			->decimal('lng')
			->allowEmpty('lng');

		$validator
			->allowEmpty('data');

		return $validator;
	}
91560
public static function validator($validator = null)
    {
        if (func_num_args()) {
            static::$_validators[static::class] = $validator;
            return;
        }
        $self = static::class;
        if (isset(static::$_validators[$self])) {
            return static::$_validators[$self];
        }
        $class = static::$_classes['validator'];
        $validator = static::$_validators[$self] = new $class();
        static::_rules($validator);
        return $validator;
    }
337711
public function validationDefault(Validator $validator)
    {
        $validator
            ->notEmpty('handler', __d('field', 'Invalid field type.'))
            ->add('label', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('field', 'You need to provide a label.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('field', 'Label need to be at least 3 characters long'),
                ],
            ]);

        return $validator;
    }
462670
public function validationAnonymous(Validator $validator)
    {
        $settings = Plugin::get('Comment')->settings;
        $validator = $this->validationDefault($validator);

        if ($settings['allow_anonymous']) {
            if ($settings['anonymous_name']) {
                $validator
                    ->requirePresence('author_name')
                    ->add('author_name', 'nameLength', [
                        'rule' => ['minLength', 3],
                        'message' => __d('comment', 'Your name need to be at least 3 characters long.'),
                    ]);

                if ($settings['anonymous_name_required']) {
                    $validator->notEmpty('author_name', __d('comment', 'You must provide your name.'));
                } else {
                    $validator->allowEmpty('author_name');
                }
            }

            if ($settings['anonymous_email']) {
                $validator
                    ->requirePresence('author_email')
                    ->add('author_email', 'validEmail', [
                        'rule' => 'email',
                        'message' => __d('comment', 'e-Mail must be valid.'),
                    ]);

                if ($settings['anonymous_email_required']) {
                    $validator->notEmpty('author_email', __d('comment', 'You must provide an email.'));
                } else {
                    $validator->allowEmpty('anonymous_email');
                }
            }

            if ($settings['anonymous_web']) {
                $validator
                    ->requirePresence('author_web')
                    ->add('author_web', 'validURL', [
                        'rule' => 'url',
                        'message' => __d('comment', 'Website must be a valid URL.'),
                    ]);

                if ($settings['anonymous_web_required']) {
                    $validator->notEmpty('author_web', __d('comment', 'You must provide a website URL.'));
                } else {
                    $validator->allowEmpty('author_web');
                }
            }
        }

        return $validator;
    }
626798
public function create($options, Context $context = null)
    {
        $validators = [];
        if (!empty($options['required'])) {
            $validators[] = new PresenceOf();
        }
        $type = ArrayHelper::fetch($options, 'type');
        if (isset($type)) {
            if ($type == 'datetime') {
                $validators[] = new Datetime([
                    'pattern' => ArrayHelper::fetch($options, 'pattern')
                ]);
            } elseif (isset(self::$TYPES[$type])) {
                $validators[] = (new self::$TYPES[$type]([]))->getValidator($this->form);
            } elseif ($type == 'array') {
                $validators[] = (new IsArray([
                    'element' => ArrayHelper::fetch($options, 'element')
                ], $context))->getValidator($this->form);
            } else {
                if ($context) {
                    $type = (new ClassResolver($this->form->getCache()))
                           ->resolve($type, $context->getDeclaringClass());
                }
                if (class_exists($type)) {
                    if (is_subclass_of($type, ValidatorInterface::class)) {
                        $validators[] = new $type($options);
                    } else {
                        $validators[] = new IsA($this->form, ['class' => $type]);
                    }
                } else {
                    if ($this->logger) {
                        $this->logger->warning("unknown validator type {$type}");
                    }
                }
            }
        }
        if (isset($options['min']) || isset($options['max'])) {
            $validators[] = new Range([
                'min' => ArrayHelper::fetch($options, 'min'),
                'max' => ArrayHelper::fetch($options, 'max'),
                'exclusiveMinimum' => ArrayHelper::fetch($options, 'exclusiveMinimum'),
                'exclusiveMaximum' => ArrayHelper::fetch($options, 'exclusiveMaximum')
            ]);
        }
        if (isset($options['minLength']) || isset($options['maxLength'])) {
            $validators[] = new StringLength([
                'min' => ArrayHelper::fetch($options, 'minLength'),
                'max' => ArrayHelper::fetch($options, 'maxLength')
            ]);
        }
        if (isset($options['enum'])) {
            if (is_array($options['enum'])) {
                $validators[] = new InclusionIn(['domain' => $options['enum']]);
            } else {
                $validators[] = (new Enum([
                    'model' => $options['enum'],
                    'attribute' => ArrayHelper::fetch($options, 'attribute'),
                ], $context))->getValidator($this->form);
            }
        }
        if (isset($options['pattern']) && $type != 'datetime') {
            $validators[] = new Regex([ 'pattern' => $options['pattern'] ]);
        }
        return $validators;
    }
144152
public function validationDefault(Validator $validator)
    {
        $validator
            ->requirePresence('name')
            ->add('name', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('content', 'You need to provide a content type name.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('content', 'Name need to be at least 3 characters long.'),
                ],
            ])
            ->requirePresence('slug', 'create')
            ->notEmpty('slug', __d('content', 'Machine-name cannot be left empty.'), 'create')
            ->add('slug', 'checkSlug', [
                'rule' => function ($value, $context) {
                    return (preg_match('/^[a-z0-9\-]{3,}$/', $value) === 1);
                },
                'message' => __d('content', 'Invalid machine-name.'),
            ])
            ->requirePresence('title_label')
            ->add('title_label', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('content', 'You need to provide a "Title Label".'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('content', '"Title Label" need to be at least 3 characters long.'),
                ],
            ]);

        return $validator;
    }
829
public function prepareValidator(\Asgard\Validation\ValidatorInterface $validator, array $locales=[]) {
		$this->getDefinition()->trigger('validation', [$this, $validator], function($chain, $entity, $validator) use($locales) {
			$messages = [];

			foreach($this->getDefinition()->properties() as $name=>$property) {
				if($locales && $property->get('i18n')) {
					foreach($locales as $locale) {
						if($property->get('many')) {
							if($this->get($name, null, false) instanceof ManyCollection) {
								foreach($this->get($name, null, false) as $k=>$v) {
									$propValidator = $validator->attribute($name.'.'.$locale.'.'.$k);
									$property->prepareValidator($propValidator);
									$propValidator->formatParameters(function(&$params) use($name) {
										$params['attribute'] = $name;
									});
									$propValidator->ruleMessages($property->getMessages());
								}
							}
						}
						else {
							$propValidator = $validator->attribute($name.'.'.$locale);
							$property->prepareValidator($propValidator);
							$propValidator->formatParameters(function(&$params) use($name) {
								$params['attribute'] = $name;
							});
							$propValidator->ruleMessages($property->getMessages());
						}
					}
				}
				else {
					if($property->get('many')) {
						if($this->get($name, null, false) instanceof ManyCollection) {
							foreach($this->get($name, null, false) as $k=>$v) {
								$propValidator = $validator->attribute($name.'.'.$k);
								$property->prepareValidator($propValidator);
								$propValidator->formatParameters(function(&$params) use($name) {
									$params['attribute'] = $name;
								});
								$propValidator->ruleMessages($property->getMessages());
							}
						}
					}
					else {
						$propValidator = $validator->attribute($name);
						$property->prepareValidator($propValidator);
						$propValidator->ruleMessages($property->getMessages());
					}
				}
			}

			$messages = array_merge($messages, $this->getDefinition()->messages());
			$validator->attributesMessages($messages);

			$validator->set('entity', $this);
		});

		return $validator;
	}