-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
property path format #462
Comments
Hi @root-aza, pinging me wont change the delay for the answer that I write during my sparetime, and is kind of a rude thing to do after such a short time. Please be careful about it 😉 Concerning your question, I don't really understand what is needed there: could you add a more detailed example of what should be changed? |
Code example<?php
declare(strict_types=1);
use CuyZ\Valinor\Mapper\MappingError;
use CuyZ\Valinor\Mapper\Source\Source;
use CuyZ\Valinor\Mapper\Tree\Message\Messages;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
include 'vendor/autoload.php';
final readonly class Country
{
/**
* @param non-empty-string $name
* @param list<City> $cities
*/
public function __construct(
public string $name,
public array $cities,
) {}
}
final readonly class City
{
/**
* @param non-empty-string $name
* @param DateTimeZone $timeZone
*/
public function __construct(
public string $name,
public DateTimeZone $timeZone,
) {}
}
$json = <<<JSON
{
"cities": [
{"name": "", "timeZone": "Europe/Paris"},
{"name": "Lyon", "timeZone": "Europe/Paris"}
]
}
JSON;
try {
$country = (new \CuyZ\Valinor\MapperBuilder())
->mapper()
->map(Country::class, Source::json($json));
echo $country->name; // France
echo $country->cities[0]->name; // Paris
} catch (MappingError $error) {
$list = new ConstraintViolationList();
foreach (Messages::flattenFromNode($error->node())->errors() as $error){
$node = $error->node();
$newPath = $node->path();
$constraint = new ConstraintViolation(
$error->toString(),
messageTemplate: null,
parameters: [],
root: null,
propertyPath: $node->path(),
invalidValue: $node->sourceFilled() ? $node->sourceValue() : null,
code: '72fb6435-c397-4dd2-a201-94c6b4973157'
);
$list->add($constraint);
}
}
but we want to get Why is this necessary? |
If I understand correctly, this is needed by the |
not really. symfony/validator initially generates a path in the format And I would like monotony |
Hi! Is it possible to somehow change the formation of the property path?
Example:
The text was updated successfully, but these errors were encountered: