-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Proposal: Add EmailAddress value object #93
Comments
Hi @ro0NL I don't fully agree with $host = $email->getHost(); // Host
$host->normalize(); //domain.com
(string)$host // domain.COM and the same for |
I like it :) This is also being discussed at symfony for their
I'm not sure the constructor needs a validator / should perform any validation, as it's a value object. I would keep it really simple; public function __construct($local, $host = null) {
if ($host === null) {
if (false === ($atPos = mb_strrpos($local, '@'))) {
throw new \DomainException('Malformed email: ' . $local . ' (missing @)');
}
$host = mb_substr($local, ($atPos + 1));
$local = mb_substr($local, 0, $atPos);
}
$this->local = $local;
$this->host = $host;
} A factory (method), i.e. About warnings, i'm not sure a VO object should depepd on any validation knowledge, as it's part of the validation process and the VO just represents data. I.e. you should get warnings from the validator when validating (it would be weird to __construct the VO with warnings yourself...), but I understand this requires some thought. Maybe public static function fromString($email, array &$warnings = null, EmailValidator $validator = null) {
// not sure about the EmailValidator internals, but you get the point
$validator = $validator ?: new EmailValidator();
$valid = $validator->isValid($email);
$warnings = $validator->getWarnings();
unset($warnings); //reference
if (!$valid) {
throw new InvalidEmailException($email, $validator);
}
return new static($email); // perhaps decompose $email here instead of in the constructor Last; the normalization thingy. What i meant was a fluent interface; public function normalize() {
$local = mb_strtolower($this->local); // whatever normalization is needed
$host = mb_strtolower($this->host); // whatever normalization is needed
return new self($local, $host);
} I think individual email part VO's ( |
About naming..i alwast thought it was;
and therefor the correct keyword should be |
Hi,
What do you think of a
EmailAddress
value object, to clearify;I think this would be a useful addition to the library...
The text was updated successfully, but these errors were encountered: