Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 4ee2d36

Browse files
author
Jens Schulze
authored
Merge pull request #269 from commercetools/subscriptions
Subscriptions
2 parents f4ac2c8 + 1d3de36 commit 4ee2d36

32 files changed

+1454
-3
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[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 getResourceTypeId()
14+
* @method ChangeSubscription setResourceTypeId(string $resourceTypeId = null)
15+
*/
16+
class ChangeSubscription extends JsonObject
17+
{
18+
public function fieldDefinitions()
19+
{
20+
return [
21+
'resourceTypeId' => [static::TYPE => 'string'],
22+
];
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Subscription;
7+
8+
use Commercetools\Core\Model\Common\Collection;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Subscription
12+
*
13+
* @method ChangeSubscriptionCollection add(ChangeSubscription $element)
14+
* @method ChangeSubscription current()
15+
* @method ChangeSubscription getAt($offset)
16+
*/
17+
class ChangeSubscriptionCollection extends Collection
18+
{
19+
protected $type = '\Commercetools\Core\Model\Subscription\ChangeSubscription';
20+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Subscription;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
use Commercetools\Core\Model\Common\Reference;
10+
11+
/**
12+
* @package Commercetools\Core\Model\Subscription
13+
*
14+
* @method string getProjectKey()
15+
* @method Delivery setProjectKey(string $projectKey = null)
16+
* @method string getNotificationType()
17+
* @method Delivery setNotificationType(string $notificationType = null)
18+
* @method Reference getReference()
19+
* @method Delivery setReference(Reference $reference = null)
20+
*/
21+
class Delivery extends JsonObject
22+
{
23+
const NOTIFICATION_TYPE = 'notificationType';
24+
const TYPE_MESSAGE = 'Message';
25+
const TYPE_RESOURCE_CREATED = 'ResourceCreated';
26+
const TYPE_RESOURCE_UPDATED = 'ResourceUpdated';
27+
const TYPE_RESOURCE_DELETED = 'ResourceDeleted';
28+
29+
public function fieldDefinitions()
30+
{
31+
return [
32+
'projectKey' => [static::TYPE => 'string'],
33+
static::NOTIFICATION_TYPE => [static::TYPE => 'string'],
34+
'reference' => [static::TYPE => '\Commercetools\Core\Model\Common\Reference'],
35+
];
36+
}
37+
38+
protected static function destinationType($typeId)
39+
{
40+
$types = [
41+
static::TYPE_MESSAGE => '\Commercetools\Core\Model\Subscription\MessageDelivery',
42+
static::TYPE_RESOURCE_CREATED => '\Commercetools\Core\Model\Subscription\ResourceCreatedDelivery',
43+
static::TYPE_RESOURCE_UPDATED => '\Commercetools\Core\Model\Subscription\ResourceUpdatedDelivery',
44+
static::TYPE_RESOURCE_DELETED => '\Commercetools\Core\Model\Subscription\ResourceDeletedDelivery',
45+
];
46+
return isset($types[$typeId]) ? $types[$typeId] : '\Commercetools\Core\Model\Subscription\Delivery';
47+
}
48+
49+
public static function fromArray(array $data, $context = null)
50+
{
51+
if (get_called_class() == 'Commercetools\Core\Model\Subscription\Delivery' &&
52+
isset($data[static::NOTIFICATION_TYPE])
53+
) {
54+
$className = static::destinationType($data[static::NOTIFICATION_TYPE]);
55+
if (class_exists($className)) {
56+
return new $className($data, $context);
57+
}
58+
}
59+
return new static($data, $context);
60+
}
61+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[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+
21+
public function fieldDefinitions()
22+
{
23+
return [
24+
'type' => [static::TYPE => 'string']
25+
];
26+
}
27+
28+
protected static function destinationType($typeId)
29+
{
30+
$types = [
31+
static::DESTINATION_SQS => '\Commercetools\Core\Model\Subscription\SQSDestination',
32+
static::DESTINATION_IRON_MQ => '\Commercetools\Core\Model\Subscription\IronMQDestination',
33+
];
34+
return isset($types[$typeId]) ? $types[$typeId] : '\Commercetools\Core\Model\Subscription\Destination';
35+
}
36+
37+
public static function fromArray(array $data, $context = null)
38+
{
39+
if (get_called_class() == 'Commercetools\Core\Model\Subscription\Destination' && isset($data[static::TYPE])) {
40+
$className = static::destinationType($data[static::TYPE]);
41+
if (class_exists($className)) {
42+
return new $className($data, $context);
43+
}
44+
}
45+
return new static($data, $context);
46+
}
47+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Subscription;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Subscription
12+
*
13+
* @method string getType()
14+
* @method IronMQDestination setType(string $type = null)
15+
* @method string getUri()
16+
* @method IronMQDestination setUri(string $uri = null)
17+
*/
18+
class IronMQDestination extends Destination
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'type' => [static::TYPE => 'string'],
24+
'uri' => [static::TYPE => 'string']
25+
];
26+
}
27+
28+
public static function ofUri($uri, Context $context = null)
29+
{
30+
return static::of($context)->setType('IronMQ')->setUri($uri);
31+
}
32+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Subscription;
7+
8+
use Commercetools\Core\Model\Common\Reference;
9+
use Commercetools\Core\Model\Common\DateTimeDecorator;
10+
11+
/**
12+
* @package Commercetools\Core\Model\Subscription
13+
*
14+
* @method string getProjectKey()
15+
* @method MessageDelivery setProjectKey(string $projectKey = null)
16+
* @method string getNotificationType()
17+
* @method MessageDelivery setNotificationType(string $notificationType = null)
18+
* @method Reference getReference()
19+
* @method MessageDelivery setReference(Reference $reference = null)
20+
* @method string getId()
21+
* @method MessageDelivery setId(string $id = null)
22+
* @method int getVersion()
23+
* @method MessageDelivery setVersion(int $version = null)
24+
* @method int getSequenceNumber()
25+
* @method MessageDelivery setSequenceNumber(int $sequenceNumber = null)
26+
* @method int getResourceVersion()
27+
* @method MessageDelivery setResourceVersion(int $resourceVersion = null)
28+
* @method DateTimeDecorator getCreatedAt()
29+
* @method MessageDelivery setCreatedAt(\DateTime $createdAt = null)
30+
* @method DateTimeDecorator getLastModifiedAt()
31+
* @method MessageDelivery setLastModifiedAt(\DateTime $lastModifiedAt = null)
32+
*/
33+
class MessageDelivery extends Delivery
34+
{
35+
public function fieldDefinitions()
36+
{
37+
$definition = parent::fieldDefinitions();
38+
$definition = array_merge(
39+
$definition,
40+
[
41+
'id' => [static::TYPE => 'string'],
42+
'version' => [static::TYPE => 'int'],
43+
'sequenceNumber' => [static::TYPE => 'int'],
44+
'resourceVersion' => [static::TYPE => 'int'],
45+
'createdAt' => [
46+
static::TYPE => '\DateTime',
47+
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
48+
],
49+
'lastModifiedAt' => [
50+
static::TYPE => '\DateTime',
51+
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
52+
],
53+
]
54+
);
55+
return $definition;
56+
}
57+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[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 getResourceTypeId()
14+
* @method MessageSubscription setResourceTypeId(string $resourceTypeId = null)
15+
* @method array getTypes()
16+
* @method MessageSubscription setTypes(array $types = null)
17+
*/
18+
class MessageSubscription extends JsonObject
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'resourceTypeId' => [static::TYPE => 'string'],
24+
'types' => [static::TYPE => 'array']
25+
];
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Subscription;
7+
8+
use Commercetools\Core\Model\Common\Collection;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Subscription
12+
*
13+
* @method MessageSubscriptionCollection add(MessageSubscription $element)
14+
* @method MessageSubscription current()
15+
* @method MessageSubscription getAt($offset)
16+
*/
17+
class MessageSubscriptionCollection extends Collection
18+
{
19+
protected $type = '\Commercetools\Core\Model\Subscription\MessageSubscription';
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Subscription;
7+
8+
use Commercetools\Core\Model\Common\Reference;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Subscription
12+
*
13+
* @method string getProjectKey()
14+
* @method ResourceCreatedDelivery setProjectKey(string $projectKey = null)
15+
* @method string getNotificationType()
16+
* @method ResourceCreatedDelivery setNotificationType(string $notificationType = null)
17+
* @method Reference getReference()
18+
* @method ResourceCreatedDelivery setReference(Reference $reference = null)
19+
* @method int getVersion()
20+
* @method ResourceCreatedDelivery setVersion(int $version = null)
21+
*/
22+
class ResourceCreatedDelivery extends Delivery
23+
{
24+
public function fieldDefinitions()
25+
{
26+
$definition = parent::fieldDefinitions();
27+
$definition['version'] = [static::TYPE => 'int'];
28+
return $definition;
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Subscription;
7+
8+
use Commercetools\Core\Model\Common\Reference;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Subscription
12+
*
13+
* @method string getProjectKey()
14+
* @method ResourceDeletedDelivery setProjectKey(string $projectKey = null)
15+
* @method string getNotificationType()
16+
* @method ResourceDeletedDelivery setNotificationType(string $notificationType = null)
17+
* @method Reference getReference()
18+
* @method ResourceDeletedDelivery setReference(Reference $reference = null)
19+
* @method int getVersion()
20+
* @method ResourceDeletedDelivery setVersion(int $version = null)
21+
*/
22+
class ResourceDeletedDelivery extends Delivery
23+
{
24+
public function fieldDefinitions()
25+
{
26+
$definition = parent::fieldDefinitions();
27+
$definition['version'] = [static::TYPE => 'int'];
28+
return $definition;
29+
}
30+
}

0 commit comments

Comments
 (0)