コード例 #1
0
 /**
  * @param ProcessEvent $event
  */
 public function onProcess(ProcessEvent $event)
 {
     $jsonResponse = $event->getResponse()->json();
     if (is_array($jsonResponse) && array_key_exists('error', $jsonResponse) && array_key_exists('errorcode', $jsonResponse)) {
         throw new BadResponseException($jsonResponse['error'], $event->getRequest());
     }
 }
コード例 #2
0
 public function checkForPermanentRedirect(ProcessEvent $e)
 {
     $res = $e->getResponse();
     if ($res && $res->getStatusCode() == 301) {
         throw new PermanentRedirectException('Encountered a permanent redirect while requesting ' . $e->getRequest()->getUrl(), $e->getTransaction());
     }
 }
コード例 #3
0
 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'];
     }
 }
コード例 #4
0
 public function testHasData()
 {
     $command = $this->getMock('GuzzleHttp\\Command\\CommandInterface');
     $client = $this->getMock('GuzzleHttp\\Command\\ServiceClientInterface');
     $trans = new CommandTransaction($client, $command);
     $request = new Request('GET', 'http://httbin.org');
     $response = new Response(200);
     $trans->setRequest($request);
     $trans->setResponse($response);
     $event = new ProcessEvent($trans);
     $this->assertSame($command, $event->getCommand());
     $this->assertSame($client, $event->getClient());
     $this->assertSame($request, $event->getRequest());
     $this->assertSame($response, $event->getResponse());
     $this->assertSame($trans, $event->getTransaction());
     $this->assertNull($event->getResult());
 }