/**
  * Parses the value as it is an instance of the class specified in type property.
  *
  * @param array|\stdClass $value The value to parse and convert to an object
  *
  * @throws \Mcustiel\SimpleRequest\Exception\InvalidAnnotationException
  *
  * @return object Parsed value as instance of class specified in type property
  */
 private function createInstanceOfTypeFromValue($value)
 {
     if (!isset($value)) {
         return null;
     }
     if (class_exists($this->type)) {
         return $this->requestBuilder->parseRequest($value, $this->type);
     }
     throw new InvalidAnnotationException("Class {$this->type} does not exist. Annotated in property {$this->name}.");
 }
 public function loadExpectationFromFile($fileName)
 {
     $this->logger->debug("Loading expectation file {$fileName}");
     $content = file_get_contents($fileName);
     $data = @json_decode($content, true);
     if (json_last_error() != JSON_ERROR_NONE) {
         throw new \Exception(json_last_error_msg());
     }
     $expectation = $this->requestBuilder->parseRequest($data, Expectation::class, RequestBuilder::RETURN_ALL_ERRORS_IN_EXCEPTION);
     $this->validateExpectationOrThrowException($expectation, $this->logger);
     $this->logger->debug('Parsed expectation: ' . var_export($expectation, true));
     $this->storage->addExpectation($expectation);
 }
 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());
     }
 }