This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Request): add generic PSR-Request
- Loading branch information
Jens Schulze
committed
Nov 9, 2016
1 parent
bdfd8c7
commit 5b374eb
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |