Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created February 6, 2011 17:52
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 kriswallsmith/813559 to your computer and use it in GitHub Desktop.
Save kriswallsmith/813559 to your computer and use it in GitHub Desktop.
<?php
interface Configurable
{
static function getOptionsBag();
}
class Form implements Configurable
{
public function __construct($options = array())
{
$this->options = static::getOptionsBag()->process($options);
}
static public function getOptionsBag()
{
return OptionsBag::create()
->addRequiredOption('foo')
->addOption('bar', 'blah')
;
}
}
@beberlei
Copy link

beberlei commented Feb 6, 2011

This does not allow for instance variables of the options but keeps the stupid $options array that has no meaning :)

@kriswallsmith
Copy link
Author

Well, that could be done in the constructor, if that's what you want. We could also add some simple "binding" logic to the options bag that sets properties on the configurable object. I don't see the problem with an options array, myself.

@beberlei
Copy link

beberlei commented Feb 6, 2011

The code is so unexplicit, when your field wiggles with 20 or something options is really bad to read getOption('a') getOption('b)' only ... and so on.

Why the static bag btw? Is there any metadata need for this? I can't really see it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment