Activate Bean Validation (JSR303)

@return ManagerFactoryBuilder
@see <a href="https://github.com/doanduyhai/Achilles/wiki/Configuration-Parameters#bean-validation" target="_blank">Bean validation</a>
550886
public T withPostLoadBeanValidation(boolean enablePostLoadBeanValidation) {
        if (enablePostLoadBeanValidation) {
            Validator.validateTrue(configMap.containsKey(BEAN_VALIDATION_ENABLE) && configMap.<Boolean>getTyped(BEAN_VALIDATION_ENABLE),
                    "Before activating Post Load Bean Validation, you should activate first Bean Validation by calling 'withBeanValidation(true)' ");
        }
        configMap.put(POST_LOAD_BEAN_VALIDATION_ENABLE, enablePostLoadBeanValidation);
        return getThis();
    }
570596
private static function validation() {
        if (isset(self::$config['validators'])) {
            $validators = self::$config['validators'];
        }
        else {
            $validators = true;
        }

        // action name validation
        if ($validators === true || (!isset($validators['actionName']) || $validators['actionName'] === true)) {
            if (substr(PHPMVC_ACTION, 0, 2) == '__') {
                throw new ActionNameValidationException();
            }
        }

        // request verification token
        $antiForgeryTokenForAction = InternalHelper::getStaticPropertyValue('\\PhpMvc\\ValidateAntiForgeryToken', 'enable');
        if ($antiForgeryTokenForAction === true || (($validators === true || (!isset($validators['antiForgeryToken']) || $validators['antiForgeryToken'] === true)) && $antiForgeryTokenForAction !== false)) {
            $request = self::$config['httpContext']->getRequest();

            if ($request->isPost()) {
                $post = $request->post();
                $expected = $request->cookies('__requestVerificationToken');

                if (!isset($post)) { $post = array(); }

                if (
                    (isset($expected) && $expected !== 'false' && (!isset($post['__requestVerificationToken']) || $post['__requestVerificationToken'] != $expected)) ||
                    (isset($expected) && $expected === 'false' && !empty($post['__requestVerificationToken'])) ||
                    (isset($post['__requestVerificationToken']) && empty($expected))
                   ) {
                    throw new HttpAntiForgeryException();
                }
            }
        }

        // cross site scripting validation
        if ($validators === true || (!isset($validators['crossSiteScripting']) || $validators['crossSiteScripting'] === true)) {
            $request = self::$config['httpContext']->getRequest();

            $get = $request->get();
            $post = $request->post();

            if (!isset($get)) { $get = array(); }
            if (!isset($post)) { $post = array(); }

            $items = array_merge($get, $post);

            foreach ($items as $key => $value) {
                $isDangerousString = CrossSiteScriptingValidation::IsDangerousString($key) || CrossSiteScriptingValidation::IsDangerousString($value);
    
                if ($isDangerousString) {
                    $source = null;

                    if (!empty($get[$key])) {
                        $source = '$_GET';
                    }
                    elseif (!empty($post[$key])) {
                        $source = '$_POST';
                    }
    
                    throw new HttpRequestValidationException($source, $key, $value);
                }
            }
        }
    }
132154
public function createValidator()
    {
        $sv = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
        $validator = new Validator($sv);

        return $validator;
    }
993196
public T withBeanValidator(javax.validation.Validator validator) {
        if (validator != null) {
            configMap.put(BEAN_VALIDATION_VALIDATOR, validator);
            configMap.put(BEAN_VALIDATION_ENABLE, true);
        }
        return getThis();
    }
408325
public function validate()
    {
        $context = array_merge(['input' => $this], $this->context);
        $values = $this->getValue();
        if (!is_array($values)) {
            $this->valid = $this->getValidationChain()
                ->validates($this->getValue(), $context);
            return $this;
        }
        $this->validateArray($values, $context);
        return $this;
    }
238773
public function getValidator(): ?Factory
    {
        if (!$this->hasValidator()) {
            $this->setValidator($this->getDefaultValidator());
        }
        return $this->validator;
    }
993885
@Override
    protected <T> T instantiateClass(Class<T> clazz) throws Throwable {
        // Get the current BeanManager for this module. If one doesn't exist it is because 
        // the module isn't CDI enabled and we fall back to the original behavior.

        ManagedObject<T> mo = null;
        if (releasableFactory != null) {
            mo = releasableFactory.createValidationReleasable(clazz);
        }

        if (mo != null) {
            if (releasables == null) {
                releasables = new LinkedList<ValidationReleasable<?>>();
            }

            // Save off the context under which the class was created as a CDI managed
            // bean so it can be cleaned up upon stopping the module.
            //releasables.add(mo);

            return mo.getObject();
        } else {
            return super.instantiateClass(clazz);
        }
    }
597531
public function register()
    {
        $this->registerPresenceVerifier();

        $this->app->bindShared('validator', function($app)
        {
            $config = $app['config'];

            // Get a Validation Factory instance.
            $validator = new Factory($config);

            if (isset($app['validation.presence'])) {
                $presenceVerifier = $app['validation.presence'];

                $validator->setPresenceVerifier($presenceVerifier);
            }

            return $validator;
        });
    }
1365765
protected function getValidatorInstance()
    {
        $factory = $this->app()->make(Factory::class);

        if (method_exists($this, 'validator')) {
            $validator = $this->app()->call([$this, 'validator'], compact('factory'));
        } else {
            $validator = $this->createDefaultValidator($factory);
        }

        if (method_exists($this, 'withValidator')) {
            $this->withValidator($validator);
        }

        return $validator;
    }
48460
public function buildFormFactory()
    {
        $this->ensureCsrfTokenManagerAndTranslatorExist();
        $validator = $this->buildValidator();
        $csrf      = new CsrfExtension(
            $this->csrf_token_manager,
            $this->translator,
            TranslatorBuilder::TRANSLATION_DOMAIN
        );
        $builder   = Forms::createFormFactoryBuilder()->addExtension($csrf)
                                            ->addExtension(new ValidatorExtension($validator))
                                            ->addExtension(new HttpFoundationExtension());
        foreach ($this->form_extensions as $extension) {
            $builder->addExtension($extension);
        }
        return $builder->getFormFactory();
    }
1083052
public static void validate(@NotNull Object bean) {
        Assert.notNull(bean, "bean不能为null");
        Set<ConstraintViolation<Object>> constraintViolations = validator.validate(bean);
        check(constraintViolations);
    }
668689
public function getValidator()
    {
        if (!($this->validator instanceof ValidatorInterface)) {
            $this->validator = ValidatorHelper::create($this->validator);
        }

        return $this->validator;
    }
1293967
public void setValidatorFactory(ValidatorFactory validatorFactory) {
		
		// Si le paramètre n'est pas null
		if(validatorFactory != null)  {
			
			// On positionne la fabrique
			this.validatorFactory = validatorFactory;
			
			// On construit le validateur
			this.validator = validatorFactory.getValidator();
		}
	}
1188127
public function getFieldsValidationActivationJavaScriptCode()
    {
        $javaScriptBlocks = [];
        $formConfiguration = $this->getFormObject()->getConfiguration();

        foreach ($formConfiguration->getFields() as $field) {
            foreach ($field->getValidation() as $validation) {
                $fieldConditionExpression = [];
                $javaScriptTree = $this->getConditionTreeForValidation($validation)->getJavaScriptConditions();

                if (false === empty($javaScriptTree)) {
                    foreach ($javaScriptTree as $node) {
                        $fieldConditionExpression[] = 'flag = flag || (' . $node . ');';
                    }

                    $javaScriptBlocks[] = $this->getSingleFieldActivationConditionFunction($validation, $fieldConditionExpression);
                }
            }
        }

        $javaScriptBlocks = implode(CRLF, $javaScriptBlocks);
        $formName = GeneralUtility::quoteJSvalue($this->getFormObject()->getName());

        return <<<JS
(function() {
    Fz.Form.get(
        $formName,
        function(form) {
            var field = null;

$javaScriptBlocks

            form.refreshAllFields();
        }
    );
})();
JS;
    }
1188863
@Override
    public ValidationResult validate(PMContext ctx) {
        final ValidationResult res = new ValidationResult();
        final Object fieldvalue = ctx.getFieldValue();
        res.setSuccessful(fieldvalue != null);
        if (!res.isSuccessful()) {
            res.getMessages().add(MessageFactory.error(
                    ctx.getEntity(), ctx.getField(),
                    get("msg", "pm.validator.not.null"),
                    ctx.getField().getId()));
        }
        return res;
    }
877532
public JmxReporter start() {
		SimonManagerMXBean simonManagerMXBean = new SimonManagerMXBeanImpl(manager);
		registerMXBean(simonManagerMXBean, beanName);

		if (registerSimons) {
			jmxRegisterCallback = new JmxRegisterCallback(beanServer, simonDomain);
			if (registerExistingSimons) {
				jmxRegisterCallback.setRegisterExisting(true);
			}
			manager.callback().addCallback(jmxRegisterCallback);
		}
		return this;
	}
30373
private Validator createDefaultValidator() {
        final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
        final Validator validator = validatorFactory.usingContext()
                .getValidator();
        
        return validator;
    }