I was not a fan of this style, but I ran across an example where it seemed to work. My original code was:
PHP Code:
$this->addParameter(new PostParameter('name', 'name'));
This caused confusion because the most common case is that the optional second parameter would be the same as the first. You could solve this by passing an array:
PHP Code:
$this->addParameter(new PostParameter(array('name'=>'name', 'modelLocation' => 'name')));
Well, I really didn't like this. It stinks when you don't specify the optional modelLocation parameter. I generally don't like passing configuration arrays to object constructors, so I went fluid:
PHP Code:
$this->addParameter(new PostParameter('name'))->setModelLocation('name');
Better, but then I adopted fluid names:
PHP Code:
$this->defineInput(new PostParameter('name'))->bindToModel('name');
Now, the most common case is that both values are the same. This can be encoded now into bindToModel, which can now have its parameter be optional. So we have:
PHP Code:
$this->defineInput(new PostParameter('name'))->bindToModel();
Better?
Bookmarks