diff --git a/src/Request/PsrRequest.php b/src/Request/PsrRequest.php new file mode 100644 index 0000000000..527ae64a95 --- /dev/null +++ b/src/Request/PsrRequest.php @@ -0,0 +1,50 @@ + + */ + +namespace Commercetools\Core\Request; + +use Commercetools\Core\Client\JsonEndpoint; +use Commercetools\Core\Model\Common\Context; +use Commercetools\Core\Response\ResourceResponse; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Commercetools\Core\Model\Common\JsonObject; +use Commercetools\Core\Response\ApiResponseInterface; +use Commercetools\Core\Model\MapperInterface; + +/** + * @package Commercetools\Core\Request + * + * @method JsonObject mapResponse(ApiResponseInterface $response) + * @method JsonObject mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) + */ +class PsrRequest extends AbstractApiRequest +{ + /** + * @var RequestInterface + */ + private $request; + + public function __construct(RequestInterface $request, Context $context = null) + { + $this->request = $request; + parent::__construct(new JsonEndpoint(''), $context); + } + + public static function ofRequest(RequestInterface $request, Context $context = null) + { + return new static($request, $context); + } + + public function buildResponse(ResponseInterface $response) + { + return new ResourceResponse($response, $this, $this->getContext()); + } + + public function httpRequest() + { + return $this->request; + } +}