Created
October 15, 2020 13:08
-
-
Save marcosh/4bfa1dbbc3bd389be67ad0b87b1db3af to your computer and use it in GitHub Desktop.
Value object external validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class Country | |
{ | |
private string $countryCode; | |
private function __construct(string $countryCode) | |
{ | |
$this->countryCode = $countryCode; | |
} | |
/** | |
* @param callable(string): bool $f | |
*/ | |
public static function existing(callable $exists, string $countryCode): self | |
{ | |
if (!$exists($countryCode)) { | |
throw new \Exception('no no no!!!') | |
} | |
return new self($countryCode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment