Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function handle(RequestInterface $request)
 {
     try {
         // @todo add request context to events ? (to carry request and response objects)
         $proxyRequestEvent = new ProxyRequestEvent($request, null, $this);
         $this->callProxyEvent($proxyRequestEvent);
         $request = $proxyRequestEvent->getRequest();
         $response = $proxyRequestEvent->getResponse();
         if (!$response) {
             $response = $this->adapter->handle($request);
         }
         $proxyResponseEvent = new ProxyResponseEvent($request, $response, $this);
         $this->callProxyEvent($proxyResponseEvent);
         $response = $proxyResponseEvent->getResponse();
     } catch (\Exception $e) {
         if ($this->debug == true) {
             throw $e;
         } else {
             $proxyExceptionEvent = new ProxyExceptionEvent($e, $request, null, $this);
             $this->callProxyEvent($proxyExceptionEvent);
             $response = $proxyExceptionEvent->getResponse();
             if (!$response) {
                 throw $this->createProxyException('Proxy failed due to an exception; it was also unable to generate error response', $e);
             }
         }
     }
     return $response;
 }
Exemplo n.º 2
0
 /**
  * @return ProxyAdapterInterface
  */
 public function getAdapter()
 {
     if (!$this->adapter) {
         $client = new Client();
         $this->adapter = new Guzzle4Adapter($client);
         $this->adapter->setLogger($this->getLogger());
     }
     return $this->adapter;
 }