|
| 1 | +<?php |
| 2 | +/** |
| 3 | + */ |
| 4 | + |
| 5 | +namespace Commercetools\Core\Request\ApiClients; |
| 6 | + |
| 7 | +use Commercetools\Core\Client\HttpMethod; |
| 8 | +use Commercetools\Core\Client\HttpRequest; |
| 9 | +use Commercetools\Core\Model\ApiClient\ApiClient; |
| 10 | +use Commercetools\Core\Model\Common\Context; |
| 11 | +use Commercetools\Core\Request\AbstractApiRequest; |
| 12 | +use Commercetools\Core\Response\ResourceResponse; |
| 13 | +use Psr\Http\Message\ResponseInterface; |
| 14 | +use Commercetools\Core\Response\ApiResponseInterface; |
| 15 | +use Commercetools\Core\Model\MapperInterface; |
| 16 | + |
| 17 | +/** |
| 18 | + * @package Commercetools\Core\Request\ApiClients |
| 19 | + * @method ApiClient mapResponse(ApiResponseInterface $response) |
| 20 | + * @method ApiClient mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
| 21 | + */ |
| 22 | +class ApiClientDeleteRequest extends AbstractApiRequest |
| 23 | +{ |
| 24 | + protected $resultClass = ApiClient::class; |
| 25 | + |
| 26 | + |
| 27 | + /** |
| 28 | + * @var string |
| 29 | + */ |
| 30 | + protected $id; |
| 31 | + |
| 32 | + /** |
| 33 | + * @param string $id |
| 34 | + * @param Context $context |
| 35 | + */ |
| 36 | + public function __construct($id, Context $context = null) |
| 37 | + { |
| 38 | + parent::__construct(ApiClientsEndpoint::endpoint(), $context); |
| 39 | + $this->setId($id); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return string |
| 44 | + */ |
| 45 | + public function getId() |
| 46 | + { |
| 47 | + return $this->id; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @param $id |
| 52 | + * @return $this |
| 53 | + */ |
| 54 | + public function setId($id) |
| 55 | + { |
| 56 | + $this->id = $id; |
| 57 | + |
| 58 | + return $this; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return string |
| 63 | + * @internal |
| 64 | + */ |
| 65 | + protected function getPath() |
| 66 | + { |
| 67 | + return (string)$this->getEndpoint() . '/' . $this->getId(); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @return HttpRequest |
| 72 | + * @internal |
| 73 | + */ |
| 74 | + public function httpRequest() |
| 75 | + { |
| 76 | + return new HttpRequest(HttpMethod::DELETE, $this->getPath()); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @param ResponseInterface $response |
| 81 | + * @return ResourceResponse |
| 82 | + * @internal |
| 83 | + */ |
| 84 | + public function buildResponse(ResponseInterface $response) |
| 85 | + { |
| 86 | + return new ResourceResponse($response, $this, $this->getContext()); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @param string $id |
| 91 | + * @param Context $context |
| 92 | + * @return static |
| 93 | + */ |
| 94 | + public static function ofId($id, Context $context = null) |
| 95 | + { |
| 96 | + return new static($id, $context); |
| 97 | + } |
| 98 | +} |
0 commit comments