|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * |
| 4 | + */ |
| 5 | + |
| 6 | +namespace Commercetools\Core\Request\InStores; |
| 7 | + |
| 8 | +use Commercetools\Core\Model\Common\Context; |
| 9 | +use Commercetools\Core\Model\MapperInterface; |
| 10 | +use Commercetools\Core\Request\ClientRequestInterface; |
| 11 | +use Commercetools\Core\Response\ApiResponseInterface; |
| 12 | +use Psr\Http\Message\RequestInterface; |
| 13 | +use Psr\Http\Message\ResponseInterface; |
| 14 | + |
| 15 | +class InStoreRequestDecorator implements ClientRequestInterface |
| 16 | +{ |
| 17 | + |
| 18 | + private $request; |
| 19 | + private $endpoint; |
| 20 | + |
| 21 | + /** |
| 22 | + * InStoreDecorator constructor. |
| 23 | + * @param string $storeKey |
| 24 | + * @param ClientRequestInterface $request |
| 25 | + */ |
| 26 | + public function __construct($storeKey, ClientRequestInterface $request) |
| 27 | + { |
| 28 | + // |
| 29 | + $this->request = $request; |
| 30 | + $this->endpoint = InStoreEndpoint::endpoint($storeKey); |
| 31 | + } |
| 32 | + |
| 33 | + public function getIdentifier() |
| 34 | + { |
| 35 | + return $this->request->getIdentifier(); |
| 36 | + } |
| 37 | + |
| 38 | + public function setIdentifier($identifier) |
| 39 | + { |
| 40 | + return $this->request->setIdentifier($identifier); |
| 41 | + } |
| 42 | + |
| 43 | + public function httpRequest() |
| 44 | + { |
| 45 | + return $this->decorateUri($this->request->httpRequest()); |
| 46 | + } |
| 47 | + |
| 48 | + private function decorateUri(RequestInterface $request) |
| 49 | + { |
| 50 | + return $request->withUri($request->getUri()->withPath($this->endpoint . $request->getUri()->getPath())); |
| 51 | + } |
| 52 | + |
| 53 | + public function buildResponse(ResponseInterface $response) |
| 54 | + { |
| 55 | + return $this->request->buildResponse($response); |
| 56 | + } |
| 57 | + |
| 58 | + public function mapResult(array $result, Context $context = null) |
| 59 | + { |
| 60 | + return $this->request->mapResult($result, $context); |
| 61 | + } |
| 62 | + |
| 63 | + public function mapResponse(ApiResponseInterface $response) |
| 64 | + { |
| 65 | + return $this->request->mapResponse($response); |
| 66 | + } |
| 67 | + |
| 68 | + public function map(array $data, Context $context = null, MapperInterface $mapper = null) |
| 69 | + { |
| 70 | + return $this->request->map($data, $context, $mapper); |
| 71 | + } |
| 72 | + |
| 73 | + public function mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
| 74 | + { |
| 75 | + return $this->request->mapFromResponse($response, $mapper); |
| 76 | + } |
| 77 | + |
| 78 | + public static function ofStoreAndRequest($storeKey, ClientRequestInterface $request) |
| 79 | + { |
| 80 | + return new static($storeKey, $request); |
| 81 | + } |
| 82 | +} |
0 commit comments