Created
April 7, 2011 10:48
-
-
Save xphere/907539 to your computer and use it in GitHub Desktop.
Validation of Value Objects
This file contains 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 | |
// With static validation, no object is created if not valid. | |
if (Locale::isValid($localeName)) { | |
$locale = new Locale($localeName); | |
doFancyStuffWith($locale); | |
} | |
// With explicit validation | |
$locale = new Locale($localeName); | |
if ($locale->isValid()) { | |
doFancyStuffWith($locale); | |
} | |
// With implicit validation, constructor throws exception on invalid locale | |
$locale = new Locale($localeName); | |
doFancyStuffWith($locale); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment