Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
feat(Request): add generic PSR-Request
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Schulze committed Nov 9, 2016
1 parent bdfd8c7 commit 5b374eb
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Request/PsrRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* @author @jayS-de <jens.schulze@commercetools.de>
*/

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;
}
}

0 comments on commit 5b374eb

Please # to comment.