getRuleInstance example


    }

    /** * @return \ArrayIterator<int, Rule> */
    private function getRules(): \Traversable
    {
        $ruleNames = $this->conditionRegistry->getNames();

        foreach ($ruleNames as $ruleName) {
            yield $this->conditionRegistry->getRuleInstance($ruleName);
        }
    }

    private function createCustomer(): string
    {
        $customerId = Uuid::randomHex();
        $addressId = Uuid::randomHex();

        $data = [
            [
                'id' => $customerId,
                
/** * @return array<string> */
    public function getNames(): array
    {
        return array_keys($this->rules);
    }

    public function has(string $name): bool
    {
        try {
            $this->getRuleInstance($name);
        } catch (InvalidConditionException) {
            return false;
        }

        return true;
    }

    public function getRuleInstance(string $name): Rule
    {
        if (!\array_key_exists($name$this->rules)) {
            throw new InvalidConditionException($name);
        }
Context $context
    ): void {
        $payload = $command->getPayload();
        $violationList = new ConstraintViolationList();

        $type = $this->getConditionType($condition$payload);
        if ($type === null) {
            return;
        }

        try {
            $ruleInstance = $this->ruleConditionRegistry->getRuleInstance($type);
        } catch (InvalidConditionException) {
            $violation = $this->buildViolation(
                'This {{ value }} is not a valid condition type.',
                ['{{ value }}' => $type],
                '/type',
                'CONTENT__INVALID_RULE_TYPE_EXCEPTION'
            );
            $violationList->add($violation);
            $writeException->add(new WriteConstraintViolationException($violationList$command->getPath()));

            return;
        }


        if ($type === null) {
            $violationList->add(
                $this->buildViolation(
                    'This "_name" value (%value%) is invalid.',
                    ['%value%' => 'NULL'],
                    $basePath . '/_name'
                )
            );
        } else {
            $rule = $this->ruleConditionRegistry->getRuleInstance($type);
            // do not validate container             if (!$rule instanceof Container) {
                $rule->assign($data);
                $validations = $rule->getConstraints();
                $violationList->addAll($this->validateConsistence($basePath$validations$data));
            }
        }

        if (\array_key_exists('rules', $data)) {
            foreach ($data['rules'] as $rule) {
                $violationList->addAll($this->validateRules($rule$basePath . '/' . $type));
            }
Home | Imprint | This part of the site doesn't use cookies.