Skip to content

Instantly share code, notes, and snippets.

@webmozart
Last active August 29, 2015 14:07
Show Gist options
  • Save webmozart/7fc967533577c6291bc0 to your computer and use it in GitHub Desktop.
Save webmozart/7fc967533577c6291bc0 to your computer and use it in GitHub Desktop.
<?php
class DefaultOptions extends Options
{
setRequired()
setDefined()
resolve()
}
<?php
class Options implements ArrayAccess, Countable
{
get()
set()
has()
merge()
replace()
}
<?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