/**
  * Execute a command and return the response
  *
  * @param CommandInterface|CommandSet|array $command Command or set to execute
  *
  * @return mixed Returns the result of the executed command's
  *       {@see CommandInterface::getResult} method if a CommandInterface is
  *       passed, or the CommandSet itself if a CommandSet is passed
  * @throws InvalidArgumentException if an invalid command is passed
  * @throws CommandSetException if a set contains commands associated
  *      with other clients
  */
 public function execute($command)
 {
     if ($command instanceof CommandInterface) {
         $command->setClient($this)->prepare();
         $this->dispatch('command.before_send', array('command' => $command));
         $command->getRequest()->send();
         $this->dispatch('command.after_send', array('command' => $command));
         return $command->getResult();
     } else {
         if ($command instanceof CommandSet) {
             foreach ($command as $c) {
                 if ($c->getClient() && $c->getClient() !== $this) {
                     throw new CommandSetException('Attempting to run a mixed-Client CommandSet from a ' . 'Client context.  Run the set using CommandSet::execute() ');
                 }
                 $c->setClient($this);
             }
             return $command->execute();
         } else {
             if (is_array($command)) {
                 return $this->execute(new CommandSet($command));
             }
         }
     }
     throw new InvalidArgumentException('Invalid command sent to ' . __METHOD__);
 }