public function testCanSetResultAndDoesNotStopPropagation() { $command = $this->getMock('GuzzleHttp\\Command\\CommandInterface'); $client = $this->getMock('GuzzleHttp\\Command\\ServiceClientInterface'); $trans = new CommandTransaction($client, $command); $result = null; $event = new ProcessEvent($trans); $event->setResult('foo'); $this->assertSame('foo', $event->getResult()); $this->assertSame('foo', $trans->getResult()); $this->assertFalse($event->isPropagationStopped()); }
public function onProcess(ProcessEvent $event) { $command = $event->getCommand(); if (!$command instanceof GuzzleCommandInterface) { throw new \RuntimeException('The command sent to ' . __METHOD__ . ' is not a GuzzleHttp\\Command\\Guzzle\\GuzzleCommandInterface'); } // Do not overwrite a previous result if ($event->getResult()) { return; } $operation = $command->getOperation(); // Add a default Model as the result if no matching schema was found. if (!($modelName = $operation->getResponseModel())) { $event->setResult(new Model(array())); return; } $model = $operation->getServiceDescription()->getModel($modelName); if (!$model) { throw new \RuntimeException("Unknown model: {$modelName}"); } $event->setResult(new Model($this->visit($model, $event))); }
public function onProcess(ProcessEvent $event) { // Only add a result object if no exception was encountered. if ($event->getException()) { return; } $command = $event->getCommand(); // Do not overwrite a previous result if ($event->getResult()) { return; } $operation = $this->description->getOperation($command->getName()); // Add a default Model as the result if no matching schema was found. if (!($modelName = $operation->getResponseModel())) { $event->setResult([]); return; } $model = $operation->getServiceDescription()->getModel($modelName); if (!$model) { throw new \RuntimeException("Unknown model: {$modelName}"); } $event->setResult($this->visit($model, $event)); }
public function onProcess(ProcessEvent $event) { $command = $event->getCommand(); if (!$command instanceof GuzzleCommandInterface) { throw new \RuntimeException('The command sent to ' . __METHOD__ . ' is not a GuzzleHttp\\Command\\Guzzle\\GuzzleCommandInterface'); } $operation = $command->getOperation(); if (!($modelName = $operation->getResponseModel())) { return; } $model = $operation->getServiceDescription()->getModel($modelName); if (!$model) { throw new \RuntimeException("Unknown model: {$modelName}"); } $event->setResult(new Model($this->visit($model, $event))); }
/** * Callback for process event. */ public function onProcess(ProcessEvent $event) { $result = $event->getResult(); !isset($result['data']) ?: $event->setResult($result['data']); }
/** * @param ProcessEvent $event Process event of the attempt. * @param array $acceptor Acceptor configuration being checked. * * @return bool */ private function matchesError(ProcessEvent $event, array $acceptor) { /** @var \Aws\Exception\AwsException $exception */ $exception = $event->getException(); if (!$exception) { return false; } $actual = $exception->getAwsErrorCode(); if ($actual == $acceptor['expected']) { $event->setResult(true); // a.k.a do not throw the exception. return true; } return false; }