|
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\DataBag\DataBag; |
|
18
|
|
|
use OAuth2Framework\Component\Core\Event\Event; |
|
19
|
|
|
use OAuth2Framework\Component\Core\Id\Id; |
|
20
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
|
21
|
|
|
use OAuth2Framework\Component\Core\Domain\DomainObject; |
|
22
|
|
|
|
|
23
|
|
|
class ClientCreatedEvent extends Event |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ClientId |
|
27
|
|
|
*/ |
|
28
|
|
|
private $clientId; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var DataBag |
|
32
|
|
|
*/ |
|
33
|
|
|
private $parameters; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var UserAccountId|null |
|
37
|
|
|
*/ |
|
38
|
|
|
private $userAccountId; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* ClientCreatedEvent constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param ClientId $clientId |
|
44
|
|
|
* @param DataBag $parameters |
|
45
|
|
|
* @param UserAccountId|null $userAccountId |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function __construct(ClientId $clientId, DataBag $parameters, ? UserAccountId $userAccountId) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->clientId = $clientId; |
|
50
|
|
|
$this->parameters = $parameters; |
|
51
|
|
|
$this->userAccountId = $userAccountId; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param ClientId $clientId |
|
56
|
|
|
* @param DataBag $parameters |
|
57
|
|
|
* @param UserAccountId|null $userAccountId |
|
58
|
|
|
* |
|
59
|
|
|
* @return ClientCreatedEvent |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function create(ClientId $clientId, DataBag $parameters, ? UserAccountId $userAccountId): self |
|
62
|
|
|
{ |
|
63
|
|
|
return new self($clientId, $parameters, $userAccountId); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function createFromJson(\stdClass $json): DomainObject |
|
70
|
|
|
{ |
|
71
|
|
|
$clientId = ClientId::create($json->domain_id); |
|
72
|
|
|
$userAccountId = null === $json->payload->user_account_id ? null : UserAccountId::create($json->payload->user_account_id); |
|
73
|
|
|
$parameters = DataBag::create((array) $json->payload->parameters); |
|
74
|
|
|
|
|
75
|
|
|
return new self( |
|
76
|
|
|
$clientId, |
|
77
|
|
|
$parameters, |
|
78
|
|
|
$userAccountId |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function getSchema(): string |
|
86
|
|
|
{ |
|
87
|
|
|
return 'https://oauth2-framework.spomky-labs.com/schemas/events/client/created/1.0/schema'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getDomainId(): Id |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->clientId; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getPayload() |
|
102
|
|
|
{ |
|
103
|
|
|
return (object) [ |
|
104
|
|
|
'user_account_id' => $this->userAccountId ? $this->userAccountId->getValue() : null, |
|
105
|
|
|
'parameters' => (object) $this->parameters->all(), |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return ClientId |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getClientId(): ClientId |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->clientId; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return DataBag |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getParameters(): DataBag |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->parameters; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return null|UserAccountId |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getOwnerId(): ? UserAccountId |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->userAccountId; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|