No description
Find a file
2025-12-18 10:10:35 +00:00
src initial commit 2025-12-17 21:38:05 +01:00
.gitignore initial commit 2025-12-17 21:38:05 +01:00
composer.json initial commit 2025-12-17 21:38:05 +01:00
composer.lock initial commit 2025-12-17 21:38:05 +01:00
index.php initial commit 2025-12-17 21:38:05 +01:00
readme.md Update readme.md 2025-12-18 10:10:35 +00:00

Assessment: VeruA DomainObjects & Validation

The following assessment may be solved with the help of additional sources, such as Q&A or LLMs but must be indicated as such.

General

In the example index.php there are three DomainObjects that are instantiated with default values. An Owner-Object and a Client-Object are build directly. The third, an Address-Object is passed into the address field of the Client-Object.

All three are then validated acording to their respective validators. The Address object is validated through the ClientValidator.

Exercises

  1. Find out where and when the default validators of a ValueObject are executed.

  2. A default validator has to check that an e-mail address is correct on the email field of Owner and of Client::Address if set, but the field can be empty.
    Implement it in the ValueObjects/Email class and use php's filter_var(FILTER_VALIDATE_EMAIL)

  3. The validation works well, but the requirements changed. Redesign it, to implement the possibility to have multiple validators at once. As an example implement a new ExportAddressValidator in addition to the standard AddressValidator that requires an e-mail address and a valid AHV-number. The goal is, to check, if a given DomainObject is valid against different validators in different circumstances, configured and executed in one run.

  4. DomainObjects are often loaded from a database with the DataMapper Pattern, where you get entire collections of DomainObjects containing more child objects. E.g. you have a collection of Invoice-Objects that contains an Owner-Object, a Client-Object that in turn contains an Address-Object.
    We need a possibility to preconfigure the validators that have to be used to validate the whole collection of DomainObjects
    This excecise is about the design decisions and not the code. Feel free to design with UML, sample code or with whatever you feel the most comfortable.

Considerations

  • Rewrite it with the possibility to have different Validators from different packages.

  • Keep in mind, that if a field is not set at all, it is never validated.