1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Request\CustomObjects; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Error\InvalidArgumentException; |
9
|
|
|
use Commercetools\Core\Model\Common\Context; |
10
|
|
|
use Commercetools\Core\Model\CustomObject\CustomObject; |
11
|
|
|
use Commercetools\Core\Model\CustomObject\CustomObjectDraft; |
12
|
|
|
use Commercetools\Core\Request\AbstractCreateRequest; |
13
|
|
|
use Commercetools\Core\Response\ApiResponseInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @package Commercetools\Core\Request\CustomObjects |
17
|
|
|
* @link https://dev.commercetools.com/http-api-projects-custom-objects.html#create-a-customobject |
18
|
|
|
* @method CustomObject mapResponse(ApiResponseInterface $response) |
19
|
|
|
*/ |
20
|
|
|
class CustomObjectCreateRequest extends AbstractCreateRequest |
21
|
|
|
{ |
22
|
|
|
protected $resultClass = '\Commercetools\Core\Model\CustomObject\CustomObject'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param CustomObjectDraft|CustomObject $customObject |
26
|
|
|
* @param Context $context |
27
|
|
|
*/ |
28
|
11 |
|
public function __construct($customObject, Context $context = null) |
29
|
|
|
{ |
30
|
11 |
|
if (!($customObject instanceof CustomObject || $customObject instanceof CustomObjectDraft)) { |
31
|
1 |
|
throw new InvalidArgumentException(); |
32
|
|
|
} |
33
|
10 |
|
parent::__construct(CustomObjectsEndpoint::endpoint(), $customObject, $context); |
34
|
10 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param CustomObjectDraft|CustomObject $customObject |
38
|
|
|
* @param Context $context |
39
|
|
|
* @return static |
40
|
|
|
*/ |
41
|
11 |
|
public static function ofObject($customObject, Context $context = null) |
42
|
|
|
{ |
43
|
11 |
|
return new static($customObject, $context); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param CustomObjectDraft $customObject |
48
|
|
|
* @param Context|null $context |
49
|
|
|
* @return static |
50
|
|
|
*/ |
51
|
|
|
public static function ofDraft(CustomObjectDraft $customObject, Context $context = null) |
52
|
|
|
{ |
53
|
|
|
return new static($customObject, $context); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|