validateProperties example

WriteParameterBag $parameters
    ): \Generator {
        $value = json_decode(json_encode($data->getValue(), \JSON_PRESERVE_ZERO_FRACTION | \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR);

        if ($value !== null) {
            if (!\array_key_exists('type', $value)) {
                throw new InvalidPriceFieldTypeException('none');
            }

            switch ($value['type']) {
                case QuantityPriceDefinition::TYPE:
                    $this->validateProperties(
                        $value,
                        QuantityPriceDefinition::getConstraints(),
                        $parameters->getPath()
                    );
                    if (!\array_key_exists('taxRules', $value)) {
                        break;
                    }

                    foreach ($value['taxRules'] as $key => $taxRule) {
                        $this->validateProperties($taxRule, TaxRule::getConstraints()$parameters->getPath() . '/taxRules/' . $key);
                    }

                    
/** * @internal */
    public function __construct(private readonly ValidatorInterface $validator)
    {
    }

    public function getViolations(array $data, DataValidationDefinition $definition, string $path = ''): ConstraintViolationList
    {
        $violations = new ConstraintViolationList();

        $violations->addAll($this->validateProperties($data$definition$path));
        $violations->addAll($this->validateSubDefinitions($data$definition$path));
        $violations->addAll($this->validateListDefinitions($data$definition$path));

        return $violations;
    }

    public function validate(array $data, DataValidationDefinition $definition, string $path = ''): void
    {
        $violations = $this->getViolations($data$definition$path);
        if ($violations->count() === 0) {
            return;
        }
Home | Imprint | This part of the site doesn't use cookies.