Closed vjik closed 1 year ago
What is prevalidation data?
Raw values and populated values can be different. My service validate raw data into populate process and then run classic validation.
For example:
final class SimpleModel implements ValidatedModelInterface
{
use ValidatedModelTrait;
public function __construct(
#[PreValidate(new Required())]
#[Length(min: 3, skipOnError: true)]
public string $a = '.',
public string $b = '.',
public string $c = '.',
) {
}
}
$service->create(SimpleModel::class, data: []);
In raw data a
not exists and Required
add error. Then length should not add error because option skipOnError
is true.
Why don't you use separate models: for user input (with raw data) and model with populated data (converted from user input)?
Why don't you use separate models: for user input (with raw data) and model with populated data (converted from user input)?
Not convient. One input model is simple.
It is a lazy approach that is convenient at first but:
Overall, I don't think it is a good idea.
Decided don't make it, because use-case is changed: if pre validation is fail then not run validation.
My suggestion: add ability add base result to
Context
and use here.Use case: input model with prevalidation raw data.