June 2017
Intermediate to advanced
394 pages
8h 52m
English
Some people understand validation as the process whereby a service validates the state of a given object. In this case, the validation conforms to a Design-by-contract approach, which consists of preconditions, postconditions, and invariants. One such way to protect a single attribute is by using Chapter 3, Value Objects. In order to make our design more flexible for change, we focus only on asserting Domain preconditions that must be met. Here, we'll be using guards as an easy way of validating the preconditions:
class Username{ const MIN_LENGTH = 5; const MAX_LENGTH = 10; const FORMAT = '/^[a-zA-Z0-9_]+$/'; private $username; public function __construct($username) { $this->setUsername($username); } private setUsername($username) ...Read now
Unlock full access