# 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](https://docs.verua.ch/latest/classes/VeruA-DomainObjects-Owner.html)-Object and a [Client](https://docs.verua.ch/latest/classes/VeruA-DomainObjects-Client.html)-Object are build directly. The third, an [Address](https://docs.verua.ch/latest/classes/VeruA-DomainObjects-Address.html)-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](src/DomainObjects/Validation/ClientValidator.php#L24). ## Exercises 1. Find out where and when the *default validators* of a `ValueObject` are executed. 1. 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)](https://www.php.net/manual/en/filter.constants.php#constant.filter-validate-email) 1. 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. 1. `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.