1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jenschude <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\Subscription; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @package Commercetools\Core\Model\Subscription |
12
|
|
|
* |
13
|
|
|
* @method string getType() |
14
|
|
|
* @method Destination setType(string $type = null) |
15
|
|
|
*/ |
16
|
|
|
class Destination extends JsonObject |
17
|
|
|
{ |
18
|
|
|
const DESTINATION_SQS = 'SQS'; |
19
|
|
|
const DESTINATION_IRON_MQ = 'IronMQ'; |
20
|
|
|
const DESTINATION_SNS = 'SNS'; |
21
|
|
|
const DESTINATION_AZURE_SERVICE_BUS = 'AzureServiceBus'; |
22
|
|
|
const DESTINATION_GOOGLE_CLOUD_PUB_SUB = 'GoogleCloudPubSub'; |
23
|
|
|
|
24
|
1 |
|
public function fieldDefinitions() |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
1 |
|
'type' => [static::TYPE => 'string'] |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected static function destinationType($typeId) |
32
|
|
|
{ |
33
|
|
|
$types = [ |
34
|
|
|
static::DESTINATION_SQS => SQSDestination::class, |
35
|
|
|
static::DESTINATION_IRON_MQ => IronMQDestination::class, |
36
|
|
|
static::DESTINATION_SNS => SNSDestination::class, |
37
|
|
|
static::DESTINATION_AZURE_SERVICE_BUS => AzureServiceBusDestination::class, |
38
|
|
|
static::DESTINATION_GOOGLE_CLOUD_PUB_SUB => GoogleCloudPubSubDestination::class, |
39
|
|
|
]; |
40
|
|
|
return isset($types[$typeId]) ? $types[$typeId] : Destination::class; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function fromArray(array $data, $context = null) |
44
|
|
|
{ |
45
|
|
|
if (get_called_class() == Destination::class && isset($data[static::TYPE])) { |
46
|
|
|
$className = static::destinationType($data[static::TYPE]); |
47
|
|
|
if (class_exists($className)) { |
48
|
|
|
return new $className($data, $context); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
return new static($data, $context); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|