@param $groups
@param  array $constraints
@return array

Replaces validation groups in constraints
2449
protected function replaceGroups($groups, array $constraints)
    {
        if (!\is_array($groups)) {
            $groups = [$groups];
        }

        /** @var \Symfony\Component\Validator\Constraint $constraint */
        foreach ($constraints as &$constraint) {
            $constraint->groups = $groups;
        }

        return $constraints;
    }
1063227
public function validate(array $data = null, array $groups = ['Default'])
    {
        $data = null === $data ? $this->originalData : $data;
        $this->data = [];

        $violations = new ViolationList();
        foreach ($this->constraints as $key => $constraints) {
            $value = array_key_exists($key, $data) ? $data[$key] : null;
            $constraints = is_array($constraints) ? $constraints : [$constraints];
            foreach ($constraints as $constraint) {
                if ($this->useConstraint($groups, $constraint)) {
                    if ($constraint->setValue($value)->validate()->isValid()) {
                        $this->data[$key] = $constraint->getValue();
                    } else {
                        $violations->add($key, $constraint->getMessages());
                    }
                }
            }
        }

        if (null !== $this->after) {
            $this->data = call_user_func_array(
                $this->after,
                [$this->data, $violations]
            );
        }

        return $violations;
    }
333051
private function groupAuthorizationChallengesPerRecordName(array $authorizationChallenges)
    {
        $groups = [];
        foreach ($authorizationChallenges as $authorizationChallenge) {
            $groups[$this->extractor->getRecordName($authorizationChallenge)][] = $authorizationChallenge;
        }

        return $groups;
    }
608171
protected function applyConstraints($data, array $groups) {
        $result = new ValidationResult();
        $data = $this->createValidationData($data);

        foreach ($groups as $group) {
            $values = $data->get($group->getName());
            $isKeyWildcard = str_ends_with($group->getName(), '.#');

            foreach ($values as $name => $value) {
                if ($isKeyWildcard) {
                    $name = s('#%s', $name);
                }

                $group->setName($name);
                $groupResult = $group->check($value, $data);

                if ($groupResult->isFailed()) {
                    $result->extend($groupResult);
                }
            }
        }

        return $this->filterResult($result);
    }
190049
protected function addForeignConstraints(&$properties, array $constraints)
    {
        foreach ($constraints as $constraint) {
            $this->addForeignConstraint($properties, $constraint)
                ->addReferencesConstraint($properties, $constraint)
                ->addOnConstraint($properties, $constraint)
                ->addOnDeleteConstraint($properties, $constraint)
                ->addOnUpdateConstraint($properties, $constraint)
                ->addFieldPropertyClousure($properties);
        }

        return $this;
    }
904824
public function validI18N(array $locales=[], $groups=[]) {
		if(!$locales)
			$locales = $this->getLocales();
		$data = $this->toArrayRawI18N($locales);
		$validator = $this->getValidator($locales);
		return $validator->valid($data, $groups);
	}
49090
protected function getValidationRules(array $fields)
    {
        $rules = [];

        foreach($fields as $field => $data){

            if($data['validate']) $rules[$field] = $data['validate'];

        }

        return $rules;
    }
753742
public function setGroups($groups)
    {
        $this->hasGroupsProperty();

        $this->groups = $groups instanceof ArrayCollection ?
            $groups :
            new ArrayCollection($groups);
    }
160686
public function hasGroups($groups)
    {
        if ($this->user() === null) {
            return null;
        }

        if (!is_array($groups)) {
            $groups = func_get_args();
        }

        // Count roles because user need user to have all roles passed as parameter
        return count(array_intersect($groups, $this->groups)) === count($groups);
    }
1241054
public function groupBy(...$groups)
    {
        foreach ($groups as $group) {
            $this->groups = array_merge(
                (array) $this->groups,
                array_wrap($group)
            );
        }

        return $this;
    }
628860
private function isArrayConstraint(Constraint $constraint): bool
    {
        return $constraint instanceof Assert\All // << Applied only on array
            || ($constraint instanceof Assert\Choice
                && true === $constraint->multiple // << expect an array multiple choices
            );
    }
1065703
protected function verifyGroupRequirements()
    {
        if (isset($this->requiredFieldsGroups)) {
            $fields = $this->requiredFieldsGroups->getArrayCopy();

            $emptyFlag = false;
            $groupsFormatted = [];

            foreach ($fields as $group => $groupFields) {
                $groupsFormatted[] = sprintf(
                    '%s (%s)',
                    ucfirst($group),
                    implode(', ', $groupFields)
                );

                foreach ($groupFields as $field) {
                    if (!empty($this->$field)) {
                        $emptyFlag = true;
                    }
                }
            }

            if (!$emptyFlag) {
                throw new \Genesis\Exceptions\ErrorParameter(
                    sprintf(
                        'One of the following group/s of field/s must be filled in: %s%s',
                        PHP_EOL,
                        implode(
                            PHP_EOL,
                            $groupsFormatted
                        )
                    ),
                    true
                );
            }
        }
    }
144876
public function validationRules(array $rules = array())
    {
        if (empty($rules)) {
            return $this->validationRules;
        }

        $this->validationRules = $rules;

        return $this;
    }
768047
public function validateRule(Rule $rule, array $restrictions = array())
    {
        /** @var \Claroline\CoreBundle\Rule\Constraints\AbstractConstraint[] $usedConstraints */
        $usedConstraints = array();
        $existedConstraints = $this->getConstraints();

        foreach ($existedConstraints as $existedConstraint) {
            if ($existedConstraint->isApplicableTo($rule)) {
                $usedConstraints[] = $existedConstraint->setRule($rule);
            }
        }

        $validatedConstraints = 0;
        $nbConstraints = count($usedConstraints);

        $associatedLogs = $this->getAssociatedLogs($usedConstraints, $restrictions);

        foreach ($usedConstraints as $usedConstraint) {
            $usedConstraint->setAssociatedLogs($associatedLogs);

            if ($usedConstraint->validate()) {
                ++$validatedConstraints;
            }
        }

        return ($validatedConstraints === $nbConstraints) ? $associatedLogs : false;
    }
518327
public function errorsI18N(array $locales=[], $groups=[]) {
		if(!$locales)
			$locales = $this->getLocales();
		$data = $this->toArrayRawI18N($locales);
		$validator = $this->getValidator($locales);

		return $validator->errors($data, $groups);
	}
1229411
public function checkConstraint($constraint)
    {
        if (!$constraint instanceof ConstraintContract && !$constraint instanceof ConstraintGroupContract) {
            throw new InvalidArgumentException("Constraint has to be Constraint or ConstraintGroup, not " . Type::of($constraint));
        }
        if ($this->allowedOperators && $constraint instanceof Constraint) {
            $constraint->allowOperators($this->allowedOperators);
        }
        return $constraint;
    }
825517
public function relationsErrors(\Asgard\Entity\Entity $entity, $groups=[]) {
		$data = [];
		$validator = $this->createValidator($entity);
		$validator->set('entity', $entity);
		$validator->set('dataMapper', $this);
		foreach($this->relations($this->getEntityDefinition($entity)) as $name=>$relation) {
			$data[$name] = $entity->get($name, null, false);
			$relation->prepareValidator($validator->attribute($name));
			$property = $this->getEntityDefinition($entity)->property($name);
			$validator->attribute($name)->ruleMessages($property->getMessages());
			$validator->attribute($name)->isNull(function(){return false;});
		}

		return $validator->errors($data, $groups);
	}