|
Forgot to reply to zf-contributors (damn Gmail). This is for the archive :)
---------- Forwarded message ---------- From: Jurian Sluiman <[hidden email]> Date: 2012/6/26 Subject: Re: [zf-contributors] Zend\Stdlib\Options To: Gary Hockin <[hidden email]> 2012/6/26 Gary Hockin <[hidden email]> Hello, As far as I understand, you have two options: 1. Instantiate the options class yourself, pass it on to the constructor 2. Use an array of options, the constructor would instantiate the options class
It would look like this: public function __construct($options = aray()) { if (is_array($options)) { $options = new HelloWorldOptions($options);
} elseif (!$options instanceof HelloWorldOptions) { throw new InvalidArgumentException('Options parameter $options must be an array or instance of HelloWorldOptions'); } $this->options = $options; } Now you can either: $foo = new HelloWorld(array( ... )); Or: $options = new HelloWorldOptions(array(....));
$foo = new HelloWorld($options); Or: $options = new HelloWorldOptions; $options->setBar($bar); $foo = new HelloWorld($options);
I would not copy over all accessors and mutators from the options class to the functional class. That's just a waste of developing time and resources. You can create an options getter:
$helloWorld->options()->setFoo($bar); I would suggest not to use a public property, as you could externally modify the options class (set it to a FooBar instance) and this will break the HelloWorld class. An options() or getOptions() method seems more appropriate.
-- Balthasar vd Polweg 56 | 2628 AW Delft | +31 6 41 79 39 69 http://juriansluiman.nl | [hidden email] | twitter.com/juriansluiman |
| Powered by Nabble | Edit this page |
