public function addObjectUrl(ProcessEvent $e) { if ($e->getException()) { return; } $name = $e->getCommand()->getName(); if ($name === 'PutObject' || $name === 'CopyObject') { $e->getResult()['ObjectURL'] = $e->getRequest()->getUrl(); } elseif ($name === 'CompleteMultipartUpload') { $e->getResult()['ObjectURL'] = $e->getResult()['Location']; } }
public function testCanCreateWithResult() { $command = $this->getMock('GuzzleHttp\\Command\\CommandInterface'); $client = $this->getMock('GuzzleHttp\\Command\\ServiceClientInterface'); $trans = new CommandTransaction($client, $command); $trans->setResult('foo'); $event = new ProcessEvent($trans); $this->assertSame('foo', $event->getResult()); }
private function parseResponse(ProcessEvent $event, $responseParserClass) { if (class_exists($responseParserClass) == false) { throw new RuntimeException("Unknown response parser: {$responseParserClass}"); } $result = $event->getResult(); if (is_array($result) && in_array(ArrayParsable::class, class_implements($responseParserClass))) { /* @var ArrayParsable $responseParserClass */ return $responseParserClass::fromArray($result); } throw new RuntimeException("Response parser {$responseParserClass} does not implement " . ArrayParsable::class); }
public function onProcess(ProcessEvent $event) { if ($event->getCommand()->getName() !== 'ReceiveMessage') { return; } $result = $event->getResult(); if (isset($result['Messages'])) { foreach ($result['Messages'] as $message) { if ($message['MD5OfBody'] != md5($message['Body'])) { throw new SqsException('Body MD5 mismatch for ' . var_export($message, true), $event->getTransaction()); } } } }
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))); }
/** * @param ProcessEvent $event * @return ResponseInterface|null */ protected function createResult(ProcessEvent $event) { // Only add a result object if no exception was encountered. if ($event->getException()) { return null; } $command = $event->getCommand(); // Do not overwrite a previous result if ($event->getResult()) { return null; } $operation = $this->description->getOperation($command->getName()); $responseClass = $operation->getResponseModel(); if ($responseClass === null) { throw new Exception\RuntimeException(sprintf('No response class configured for operation "%s"', $command->getName())); } if (!class_exists($responseClass)) { throw new Exception\RuntimeException(sprintf('Response class "%s" of operation "%s" does not exist', $responseClass, $command->getName())); } /** @todo We could check if the response class implements ResponseInterface */ /** @var ResponseInterface $responseClass */ return $responseClass::fromOperation($operation, $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)); }
/** * 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 matchesPathAny(ProcessEvent $event, array $acceptor) { if (!$event->getResult()) { return false; } $actuals = $event->getResult()->search($acceptor['argument']) ?: []; foreach ($actuals as $actual) { if ($actual == $acceptor['expected']) { return true; } } return false; }