requiresValidation example

EntityExistence $existence,
        KeyValuePair $data,
        WriteParameterBag $parameters
    ): \Generator {
        if (!$field instanceof PriceField) {
            throw DataAbstractionLayerException::invalidSerializerField(PriceField::class$field);
        }

        $value = $data->getValue();

        /** @var JsonField $field */
        if ($this->requiresValidation($field$existence$value$parameters)) {
            if ($value !== null) {
                foreach ($value as &$row) {
                    unset($row['extensions']);
                }
            }
            $data->setValue($value);

            if ($field->is(Required::class)) {
                $this->validate([new NotBlank()]$data$parameters->getPath());
            }

            


        $parent = $parameters->getDefinition()->getParentDefinition();

        $field = $parent->getFields()->get($field->getPropertyName());

        return $field->is(Inherited::class);
    }

    protected function validateIfNeeded(Field $field, EntityExistence $existence, KeyValuePair $data, WriteParameterBag $parameters): void
    {
        if (!$this->requiresValidation($field$existence$data->getValue()$parameters)) {
            return;
        }

        $constraints = $this->getCachedConstraints($field);

        $this->validate($constraints$data$parameters->getPath());
    }

    /** * @return Constraint[] */
    
 \Generator {
        if (!$field instanceof FkField) {
            throw DataAbstractionLayerException::invalidSerializerField(FkField::class$field);
        }

        $value = $data->getValue();

        if ($this->shouldUseContext($field$data->isRaw()$value)) {
            try {
                $value = $parameters->getContext()->get($field->getReferenceDefinition()->getEntityName()$field->getReferenceField());
            } catch (\InvalidArgumentException) {
                if ($this->requiresValidation($field$existence$value$parameters)) {
                    $this->validate($this->getConstraints($field)$data$parameters->getPath());
                }
            }
        }

        if ($value === null) {
            yield $field->getStorageName() => null;

            return;
        }
        if ($this->requiresValidation($field$existence$value$parameters)) {
            
Home | Imprint | This part of the site doesn't use cookies.