/** * Checks if there are invalid values in the request, in that case it throws * an exception. * * @param array $invalidValues * * @throws \Mcustiel\SimpleRequest\Exception\InvalidRequestException */ private function checkIfRequestIsValidOrThrowException($invalidValues) { if (!empty($invalidValues)) { $exception = new InvalidRequestException('Errors occurred while parsing the request'); $exception->setErrors($invalidValues); throw $exception; } }
/** * Parses a request and returns the object obtained. * * @param array|\stdClass $request * * @return object */ public function parse($request) { $object = clone $this->requestObject; foreach ($this->propertyParsers as $propertyParser) { try { $this->setProperty($request, $object, $propertyParser); } catch (InvalidValueException $e) { $propertyName = $propertyParser->getName(); $exception = new InvalidRequestException($propertyName . ': ' . $e->getMessage()); $exception->setErrors([$propertyName => $e->getMessage()]); throw $exception; } } return clone $object; }