Skip to content

Match condition for Symfony Uuid #23

@rela589n

Description

@rela589n

Currently, the only way code could capture invalid Uuid is by placing attributes on the field, and running the validator:

#[Assert\NotBlank]
#[Assert\Uuid]
public string $id;
$command = new RegisterUserCommand($id, $login, $password);
$validator->validate($command);

If the project doesn't want to use validator directly on the commands,
it would make sense to use #[Capture attribute on $id field:

use Symfony\Component\Uid\Exception\InvalidArgumentException as InvalidUidException;

#[ExceptionalValidation]
class Item
{
  #[Capture(InvalidUidException::class)]
  public string $id;
}

In current situation, the only way to know whether the exception actually belongs to the uuid is by parsing the message from InvalidUidException.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions