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