1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Boris Guéry <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Bgy\OAuth2; |
7
|
|
|
|
8
|
|
|
class InputDataBag implements \ArrayAccess |
9
|
|
|
{ |
10
|
|
|
// known properties, sensible defaults |
11
|
|
|
const CLIENT_ID = 'client_id'; |
12
|
|
|
const CLIENT_SECRET = 'client_secret'; |
13
|
|
|
const GRANT_TYPE = 'grant_type'; |
14
|
|
|
const USERNAME = 'username'; |
15
|
|
|
const PASSWORD = 'password'; |
16
|
|
|
const REFRESH_TOKEN = 'refresh_token'; |
17
|
|
|
const RESPONSE_TYPE = 'response_type'; |
18
|
|
|
const CODE = 'code'; |
19
|
|
|
const REDIRECT_URI = 'redirect_uri'; |
20
|
|
|
|
21
|
|
|
private $data; |
22
|
|
|
|
23
|
|
|
public function __construct(array $data) |
24
|
|
|
{ |
25
|
|
|
$this->data = $data; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function get($property, $default = null) |
29
|
|
|
{ |
30
|
|
|
return isset($this->data[$property]) ? $this->data[$property] : $default; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function all() |
34
|
|
|
{ |
35
|
|
|
return $this->data; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getClientId() |
39
|
|
|
{ |
40
|
|
|
return $this->get(self::CLIENT_ID); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getClientSecret() |
44
|
|
|
{ |
45
|
|
|
return $this->get(self::CLIENT_SECRET); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getGrantType() |
49
|
|
|
{ |
50
|
|
|
return $this->get(self::GRANT_TYPE); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getUsername() |
54
|
|
|
{ |
55
|
|
|
return $this->get(self::USERNAME); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getPassword() |
59
|
|
|
{ |
60
|
|
|
return $this->get(self::PASSWORD); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getResponseType() |
64
|
|
|
{ |
65
|
|
|
return $this->get(self::RESPONSE_TYPE); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getCode() |
69
|
|
|
{ |
70
|
|
|
return $this->get(self::CODE); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getRefreshToken() |
74
|
|
|
{ |
75
|
|
|
return $this->get(self::REFRESH_TOKEN); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getRedirectUri() |
79
|
|
|
{ |
80
|
|
|
return $this->get(self::REDIRECT_URI); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function offsetExists($offset) |
84
|
|
|
{ |
85
|
|
|
return isset($this->data[$offset]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function offsetGet($offset) |
89
|
|
|
{ |
90
|
|
|
return $this->get($offset); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function offsetSet($offset, $value) |
94
|
|
|
{ |
95
|
|
|
throw new \LogicException(sprintf('Cannot set "%s", InputDataBag is immutable.', $offset)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function offsetUnset($offset) |
99
|
|
|
{ |
100
|
|
|
throw new \LogicException(sprintf('Cannot unset "%s", InputDataBag is immutable.', $offset)); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|