コード例 #1
0
 /**
  * {@inheritdoc}
  */
 protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
 {
     try {
         $this->eventDispatcher->dispatch(Events::REQUEST_CREATED, $requestCreatedEvent = new RequestCreatedEvent($this, $internalRequest));
         $response = parent::doSendInternalRequest($requestCreatedEvent->getRequest());
         $this->eventDispatcher->dispatch(Events::REQUEST_SENT, $requestSentEvent = new RequestSentEvent($this, $requestCreatedEvent->getRequest(), $response));
         if ($requestSentEvent->hasException()) {
             throw $requestSentEvent->getException();
         }
         $response = $requestSentEvent->getResponse();
     } catch (HttpAdapterException $e) {
         $e->setRequest($internalRequest);
         $e->setResponse(isset($response) ? $response : null);
         $this->eventDispatcher->dispatch(Events::REQUEST_ERRORED, $exceptionEvent = new RequestErroredEvent($this, $e));
         if ($exceptionEvent->hasResponse()) {
             return $exceptionEvent->getResponse();
         }
         throw $exceptionEvent->getException();
     }
     return $response;
 }
コード例 #2
0
 /**
  * On request created event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestCreatedEvent $event The request created event.
  */
 public function onRequestCreated(RequestCreatedEvent $event)
 {
     $event->setRequest($this->cookieJar->populate($event->getRequest()));
 }
コード例 #3
0
 /**
  * On request created event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestCreatedEvent $event The request created event.
  */
 public function onRequestCreated(RequestCreatedEvent $event)
 {
     $event->setRequest($this->getTimer()->start($event->getRequest()));
 }
コード例 #4
0
 /**
  * On request created event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestCreatedEvent $event The request created event.
  */
 public function onRequestCreated(RequestCreatedEvent $event)
 {
     $event->setRequest($this->basicAuth->authenticate($event->getRequest()));
 }
コード例 #5
0
 /**
  * Creates a request sent event.
  *
  * @param \Ivory\HttpAdapter\HttpAdapterInterface             $httpAdapter The http adapter.
  * @param \Ivory\HttpAdapter\Message\InternalRequestInterface $request     The request.
  * @param \Ivory\HttpAdapter\Message\ResponseInterface        $response    The response.
  */
 public function __construct(HttpAdapterInterface $httpAdapter, InternalRequestInterface $request, ResponseInterface $response)
 {
     parent::__construct($httpAdapter, $request);
     $this->setResponse($response);
 }
コード例 #6
0
 /**
  * On request created event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestCreatedEvent $event The event.
  */
 public function onRequestCreated(RequestCreatedEvent $event)
 {
     $this->stopwatch->start($this->getStopwatchName($event->getHttpAdapter(), $event->getRequest()));
 }
コード例 #7
0
 /**
  * On pre send event.
  *
  * @param RequestCreatedEvent $event The pre send event.
  *
  * @throws TapeRecorderException|HttpAdapterException
  */
 public function onPreSend(RequestCreatedEvent $event)
 {
     if (!$this->isRecording) {
         return;
     }
     $request = $event->getRequest();
     if ($this->currentTape->hasTrackForRequest($request) && $this->recordingMode !== self::RECORDING_MODE_OVERWRITE) {
         $track = $this->currentTape->getTrackForRequest($request);
         $this->currentTape->play($track);
     }
     $this->currentTape->startRecording($request);
 }