public function execute(CommandInterface $command)
 {
     $t = new CommandTransaction($this, $command);
     CommandEvents::prepare($t);
     // Listeners can intercept the event and inject a result. If that
     // happened, then we must not emit further events and just
     // return the result.
     if (null !== ($result = $t->getResult())) {
         return $result;
     }
     $t->setResponse($this->client->send($t->getRequest()));
     CommandEvents::process($t);
     return $t->getResult();
 }
 public function testEmitsProcessEvent()
 {
     $req = new Request('GET', 'http://httbin.org');
     $res = new Response(200);
     $client = $this->getMockForAbstractClass('GuzzleHttp\\Command\\ServiceClientInterface');
     $cmd = new Command('foo', []);
     $trans = new CommandTransaction($client, $cmd);
     $trans->setRequest($req);
     $trans->setResponse($res);
     $c = false;
     $cmd->getEmitter()->on('process', function (ProcessEvent $e) use(&$c, $client, $cmd, $req, $res) {
         $e->setResult('foo');
         $this->assertSame($client, $e->getClient());
         $this->assertSame($cmd, $e->getCommand());
         $this->assertSame($req, $e->getRequest());
         $this->assertSame($res, $e->getResponse());
         $c = true;
     });
     CommandEvents::process($trans);
     $this->assertEquals('foo', $trans->getResult());
     $this->assertTrue($c);
 }
 /**
  * Set the current request of the iterator and hook the request's event
  * system up to the command's event system.
  */
 private function processCurrentRequest(CommandTransaction $trans)
 {
     $this->currentRequest = $trans->getRequest();
     if ($this->currentRequest) {
         // Emit the command's process event when the request completes
         $this->currentRequest->getEmitter()->on('complete', function (CompleteEvent $event) use($trans) {
             $trans->setResponse($event->getResponse());
             CommandEvents::process($trans);
         });
     }
 }