Skip to content

Instantly share code, notes, and snippets.

@marcosh
Created October 15, 2020 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcosh/4bfa1dbbc3bd389be67ad0b87b1db3af to your computer and use it in GitHub Desktop.
Save marcosh/4bfa1dbbc3bd389be67ad0b87b1db3af to your computer and use it in GitHub Desktop.
Value object external validation
<?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