trq Posted December 13, 2011 Share Posted December 13, 2011 Proof of ownership: http://thorpesystems.com/phpfreaks.html Beta code I would appreciate feedback on: http://thorpesystems.com/2011/12/further-prototyping-options Link to comment https://forums.phpfreaks.com/topic/253078-pretty-keen-to-get-some-feedback-on-this-prototype/ Share on other sites More sharing options...
sandeep529 Posted December 17, 2011 Share Posted December 17, 2011 Hi, I havent used traits yet to implement anything..so pls excuse any inexperience with it...but I was thinking if the options object is necessary. I mean can its use be simplified as class Foo { use Options; public function __construct(array $options = array()) { $this->setDefaults([ 'foo' => 'foo' , 'bar' => ['required'=>true], 'boo' => ['required'=>true,'type'=>'Something'] ]); $this->setOptions($options); } } And in trait definition private function setOptions(array $options) { foreach ($options as $key => $value) { if (isset($this->options[$key])) { //validate if the value passed in $options for $key is the type specified in $this->options[$key] } else { $this->options[$key] = $value; } } } Regards, Sandeep Link to comment https://forums.phpfreaks.com/topic/253078-pretty-keen-to-get-some-feedback-on-this-prototype/#findComment-1298753 Share on other sites More sharing options...
trq Posted December 17, 2011 Author Share Posted December 17, 2011 Yeah, I have already toyed with a similar idea (see the botton of the blog post). The only problem is, it becomes difficult to tell if the array you have set for the 'bar' option defines default values 9as you posted) or is actually the default value for 'bar' itself. I am going to stick with going down the Option object path, even though it does meen an extra dependency. Link to comment https://forums.phpfreaks.com/topic/253078-pretty-keen-to-get-some-feedback-on-this-prototype/#findComment-1298913 Share on other sites More sharing options...
sandeep529 Posted December 19, 2011 Share Posted December 19, 2011 The only problem is, it becomes difficult to tell if the array you have set for the 'bar' option defines default values 9as you posted) or is actually the default value for 'bar' itself. Why not solve this by specifying the default value in the 'default' key . Ie This defaults aray would become $this->setDefaults([ 'foo' => ['default'=>'foo' ], 'bar' => ['required'=>true], 'boo' => ['required'=>true,'type'=>'Something'] ]) Link to comment https://forums.phpfreaks.com/topic/253078-pretty-keen-to-get-some-feedback-on-this-prototype/#findComment-1299228 Share on other sites More sharing options...
trq Posted December 19, 2011 Author Share Posted December 19, 2011 Yeah, I've been down that road a little too. I've been playing with these ideas for the last few days and am still convinced that I'll stick with the extra dependency on the Option object. It just seems the cleanest and with the DI ideas I also have kicking around it will be easy enough to override Option if required. Link to comment https://forums.phpfreaks.com/topic/253078-pretty-keen-to-get-some-feedback-on-this-prototype/#findComment-1299279 Share on other sites More sharing options...
Recommended Posts