Page 1 of 1

[SOLVED] Chain of command where valid return may be empty

Posted: Sun Apr 13, 2008 7:01 am
by Chris Corbyn
I think this would be classified as chain of command, although it's kind of like the strategy too.

Code: Select all

interface Command {
  public function execute($data);
}
 
...
public function whatever($data) {
  foreach ($this->_commands as $command) {
    if ($ret = $command->execute($data)) {
      return $ret;
    }
  }
}
That works well when you expect a return value, but what if you don't expect a return value and the chain still has to be broken?

EDIT | Sorry, having a blonde moment; I should be using a filter chain.

Re: [SOLVED] Chain of command where valid return may be empty

Posted: Sun Apr 13, 2008 8:10 am
by matthijs
Isn't easy isn't it, after a few nights partying? :)

Re: [SOLVED] Chain of command where valid return may be empty

Posted: Sun Apr 13, 2008 8:31 am
by Chris Corbyn
matthijs wrote:Isn't easy isn't it, after a few nights partying? :)
That's how I roll ;)