public function createResponse(Expectation $expectation, TransactionData $transactionData)
 {
     $responseConfig = $expectation->getResponse();
     $httpResponse = $transactionData->getResponse();
     $httpResponse = $this->getResponseWithBody($expectation, $httpResponse, $transactionData->getRequest());
     $httpResponse = $this->getResponseWithStatusCode($responseConfig, $httpResponse);
     $httpResponse = $this->getResponseWithHeaders($responseConfig, $httpResponse);
     $this->processDelay($responseConfig);
     return $httpResponse;
 }
 /**
  *
  * {@inheritDoc}
  *
  * @see \Mcustiel\PowerRoute\Actions\ActionInterface::execute()
  */
 public function execute(TransactionData $transactionData, $argument = null)
 {
     $this->logger->debug('Searching matching expectation for request');
     $request = $transactionData->getRequest();
     $this->logger->info('Request received: ' . $this->getLoggableRequest($request));
     $foundExpectation = $this->searchForMatchingExpectation($request);
     if ($foundExpectation === null) {
         $transactionData->set('foundExpectation', false);
         return;
     }
     $transactionData->set('foundExpectation', $foundExpectation);
 }
 protected function processAndGetResponse(TransactionData $transactionData, callable $process)
 {
     try {
         /**
          * @var \Mcustiel\Phiremock\Domain\Expectation $expectation
          */
         $expectation = $this->requestBuilder->parseRequest($this->parseJsonBody($transactionData->getRequest()), Expectation::class, RequestBuilder::RETURN_ALL_ERRORS_IN_EXCEPTION);
         $this->logger->debug('Parsed expectation: ' . var_export($expectation, true));
         return $process($transactionData, $expectation);
     } catch (InvalidRequestException $e) {
         $this->logger->warning('Invalid request received');
         return $this->constructErrorResponse($e->getErrors(), $transactionData->getResponse());
     } catch (\Exception $e) {
         $this->logger->warning('An unexpected exception occurred: ' . $e->getMessage());
         return $this->constructErrorResponse([$e->getMessage()], $transactionData->getResponse());
     }
 }
 /**
  *
  * {@inheritdoc}
  *
  * @see \Mcustiel\Phiremock\Server\Utils\Strategies\ResponseCreatorInterface::createResponse()
  */
 public function createResponse(Expectation $expectation, TransactionData $transactionData)
 {
     $url = $expectation->getProxyTo();
     $this->logger->debug('Proxying request to : ' . $url);
     return $this->httpService->send($transactionData->getRequest()->withUri(new Uri($url)));
 }
 /**
  * {@inheritDoc}
  *
  * @see \Mcustiel\PowerRoute\Actions\ActionInterface::execute()
  */
 public function execute(TransactionData $transactionData, $argument = null)
 {
     $this->requestsStorage->addRequest($transactionData->getRequest());
 }