Last active
August 29, 2015 14:07
-
-
Save webmozart/7fc967533577c6291bc0 to your computer and use it in GitHub Desktop.
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 | |
class DefaultOptions extends Options | |
{ | |
setRequired() | |
setDefined() | |
resolve() | |
} |
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 | |
class Options implements ArrayAccess, Countable | |
{ | |
get() | |
set() | |
has() | |
merge() | |
replace() | |
} |
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 | |
class Mailer | |
{ | |
// ... | |
public function __construct(array $options = array()) | |
{ | |
$defaultOptions = new DefaultOptions(); | |
$this->setDefaultOptions($defaultOptions); | |
$this->options = $defaultOptions->resolve($options); | |
} | |
protected function setDefaultOptions(DefaultOptions $options) | |
{ | |
$options['host'] = 'smtp.example.org'; | |
$options['username'] = 'user'; | |
$options['password'] = 'pa$$word'; | |
$options['port'] = function (Options $options) { | |
// ... | |
}; | |
$options['encryption'] = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment