1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\Core\Client\Event; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
17
|
|
|
use OAuth2Framework\Component\Core\Event\Event; |
18
|
|
|
use OAuth2Framework\Component\Core\Id\Id; |
19
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
20
|
|
|
use OAuth2Framework\Component\Core\Domain\DomainObject; |
21
|
|
|
|
22
|
|
|
class ClientOwnerChangedEvent extends Event |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ClientId |
26
|
|
|
*/ |
27
|
|
|
private $clientId; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var UserAccountId |
31
|
|
|
*/ |
32
|
|
|
private $newOwnerId; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* ClientOwnerChangedEvent constructor. |
36
|
|
|
* |
37
|
|
|
* @param ClientId $clientId |
38
|
|
|
* @param UserAccountId $newOwnerId |
39
|
|
|
*/ |
40
|
|
|
protected function __construct(ClientId $clientId, UserAccountId $newOwnerId) |
41
|
|
|
{ |
42
|
|
|
$this->clientId = $clientId; |
43
|
|
|
$this->newOwnerId = $newOwnerId; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public static function getSchema(): string |
50
|
|
|
{ |
51
|
|
|
return 'https://oauth2-framework.spomky-labs.com/schemas/events/client/owner-changed/1.0/schema'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param ClientId $clientId |
56
|
|
|
* @param UserAccountId $newOwnerId |
57
|
|
|
* |
58
|
|
|
* @return ClientOwnerChangedEvent |
59
|
|
|
*/ |
60
|
|
|
public static function create(ClientId $clientId, UserAccountId $newOwnerId): self |
61
|
|
|
{ |
62
|
|
|
return new self($clientId, $newOwnerId); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public static function createFromJson(\stdClass $json): DomainObject |
69
|
|
|
{ |
70
|
|
|
$clientId = ClientId::create($json->domain_id); |
71
|
|
|
$userAccountId = null === $json->payload->new_owner_id ? null : UserAccountId::create($json->payload->new_owner_id); |
72
|
|
|
|
73
|
|
|
return new self( |
74
|
|
|
$clientId, |
75
|
|
|
$userAccountId |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function getDomainId(): Id |
83
|
|
|
{ |
84
|
|
|
return $this->getClientId(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return ClientId |
89
|
|
|
*/ |
90
|
|
|
public function getClientId(): ClientId |
91
|
|
|
{ |
92
|
|
|
return $this->clientId; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return UserAccountId |
97
|
|
|
*/ |
98
|
|
|
public function getNewOwnerId(): UserAccountId |
99
|
|
|
{ |
100
|
|
|
return $this->newOwnerId; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function getPayload() |
107
|
|
|
{ |
108
|
|
|
return (object) [ |
109
|
|
|
'new_owner_id' => $this->newOwnerId->getValue(), |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|