@param \Claroline\CoreBundle\Rule\Entity\Rule $rule
@param array                                  $restrictions

@return bool|Log[]
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;
    }
1346125
protected function getValueFromRule($rule)
    {
        $value = $this->getRuleValue($rule);

        if (isset($this->operators[$rule->operator]['accept_values'])
            && $this->operators[$rule->operator]['accept_values'] === false) {
            return $this->operatorValueWhenNotAcceptingOne($rule);
        }

        return $this->getCorrectValue($rule->operator, $rule, $value);
    }
1320055
public function optimize(array $rules): array
    {
        assert(empty($rules) === false);

        $ruleId       = 0;
        $rawTargets   = [];
        $encodedRules = [];
        foreach ($rules as $rule) {
            /** @var RuleInterface $rule */
            $rawTargets[$ruleId]   = $rule->getTarget();
            $encodedRules[$ruleId] = Encoder::encodeRule($rule);
            $ruleId++;
        }

        $callable         = static::METHOD;
        $optimizedTargets = $this->optimizeTargets($rawTargets);

        /** @var callable|array $callable */
        assert($callable !== null && is_array($callable) === true &&
            is_callable($callable) === true && count($callable) === 2 &&
            is_string($callable[0]) === true && is_string($callable[1]) === true);

        return [
            static::INDEX_TARGETS  => $optimizedTargets,
            static::INDEX_RULES    => $encodedRules,
            static::INDEX_CALLABLE => $callable,
        ];
    }
580502
public function loadRuleTargetsData(Rule $rule): array
    {
        $query = $this->getTargetSelectQuery();
        $query->where(
            $query->expr()->eq('rule_id', ':rule_id')
        )
        ->setParameter('rule_id', $rule->id, Type::INTEGER)
        ->orderBy('id', 'ASC');

        $this->applyStatusCondition($query, $rule->status);

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
658510
private function formatRule($rules)
    {
        if (is_array($rules)) {
            foreach ($rules as $rule) {
                $formatted[] = $this->formatRule($rule);
            }

            return $formatted ?? [];
        }

        if (is_object($rules) || is_callable($rules)) {
            return $rules;
        }

        if (Str::contains($rules, 'required_if') && preg_match('/(.*):(.*),(.*)/', $rules, $matches)) {
            $column = Str::startsWith($matches[2], '*.') ? $matches[2] : '*.' . $matches[2];

            return $matches[1] . ':' . $column . ',' . $matches[3];
        }

        return $rules;
    }
553897
protected function indexRules(array $rules)
    {        
        $this->indexedRules = array();
        
        foreach($rules as $rule){
            if(isset($this->indexedRules[$rule[self::LOOKUP_CHAR]])){
                $this->indexedRules[$rule[self::LOOKUP_CHAR]][] = $rule;
            } else {
                $this->indexedRules[$rule[self::LOOKUP_CHAR]] = array($rule);
            }
        }       
    }
1232010
protected function parseValidationRule($rule)
	{
		$ruleArray = ['name' => '', 'parameters' => []];

		$explodedRule = explode(':', $rule);
		$ruleArray['name'] = array_shift($explodedRule);
		$ruleArray['parameters'] = explode(',', array_shift($explodedRule));

		return $ruleArray;
	}
458989
public function converterRule($rule) {
        if (!is_array($rule)) {
            $rule = explode('|', $rule);
        }
        $rules = [];
        $message = null;
        foreach ($rule as $key => $item) {
            if (!is_integer($key)) {
                $rules[$key] = $item;
                continue;
            }
            if (is_callable($item)) {
                $rules[] = $item;
            }
            if (!is_string($item) || strpos($item, ':') === false) {
                $rules[$item] = [];
                continue;
            }
            list($key, $val) = explode(':', $item, 2);
            if ($key == 'message') {
                $message = $val;
                continue;
            }
            $rules[$key] = explode(',', $val);
        }
        return compact('rules', 'message');
    }
182592
public function removeRuleFromItems($rule) {
		$result = $this->repository->removeRuleFromItems($rule);
		$this->domain->const->generateAll();
		return $result;
	}
583737
protected function resolveRule($rule)
    {

        $validation = [];
        if (is_array($rule)) {
            return $validation;
        }
        switch ($rule) {
            case 'required':
                $validation['required'] = 'required';
                break;
            default:
                if (str_contains($rule, ':') && !str_contains($rule, 'unique')) {
                    list($name, $value) = explode(':', $rule);
                    $validation["data-{$name}length"] = $value;
                }
                break;
        }
        return $validation;
    }
1076981
protected function explodeRules( $rules )
	{
		foreach ( $rules as $key => $rule )
		{
			if ( Str::contains( $key, '*' ) )
			{
				$this->each( $key, [$rule] );

				unset( $rules[$key] );
			}
			else
			{
				$rules[$key] = ( is_string( $rule ) ) ? explode( '|', $rule ) : $rule;
			}
		}

		return $rules;
	}
370448
public function getRuleProperties(AbstractRule $rule)
    {
        $properties = array();
        if (!is_null($rule->getService())) {
            $service = $this->container->get($rule->getService());
            if ($service instanceof RuleServiceInterface) {
                $properties = $service->getJsProperties($rule);
            }
        }

        return array_merge($rule->getJsProperties(), $properties);
    }
1080002
public function checkRules($rules, Array $params = null)
    {
        if (is_string($rules)) {
            $rules = (array)explode(',', $rules);
        }

        foreach ($rules as $name) {
            if (!$this->hasRule($name) || !$this->getRule($name)->execute($this, $params)) {
                return false;
            }
        }

        return true;
    }
832542
public function withRule(Rule $rule): RulesCollection
    {
        $rules = array_merge($this->rules, [$rule]);

        return new RulesCollection($rules);
    }
90205
public static function callRuleAlgorithm(
        ContextInterface $context,
        array $rulesData,
        LoggerInterface $logger = null
    ): array {
        return static::callAlgorithm(
            static::getCallable($rulesData),
            $context,
            static::getTargets($rulesData),
            static::getRules($rulesData),
            $logger
        );
    }
283687
protected function getEntity(Rule $rule)
    {
        if ($rule instanceof RuleSet) {
            foreach ($rule->getChildren() as $child) {
                return $child->getEntity();
            }

            throw new \Exception(sprintf('The rule %s and non of its children have an entity', get_class($rule)));
        }

        return $rule->getEntity();
    }
838017
public function extract_first($rules)
    {
        if ($this->_nodes) {
            $selector = new Selector($this->_document, current($this->_nodes));
            return $selector->extract($rules);
        } else {
            return [];
        }
    }