-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenFactory.php
More file actions
114 lines (99 loc) · 2.33 KB
/
Copy pathTokenFactory.php
File metadata and controls
114 lines (99 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Lasso\Oauth2ClientBundle;
use Lasso\Oauth2ClientBundle\Token;
use Buzz\Browser;
use StdClass;
/**
* Class TokenFactory
*
* @package Lasso\Oauth2ClientBundle
*/
class TokenFactory
{
/**
* The original configuration that was passed to the constructor
*
* @var \StdClass
*/
protected $originalTokenConfig;
/**
* The current configuration that may have been altered from the
* original configuration. Will be reset to the original configuration
* after every 'create' call.
*
* @var \StdClass
*/
protected $tokenConfig;
protected $browser;
/**
* @param string $clientId
* @param string $clientSecret
* @param string $tokenUrl
* @param Browser $browser
*/
public function __construct(
$clientId,
$clientSecret,
$tokenUrl,
$browser
)
{
$this->originalTokenConfig = new StdClass();
$this->originalTokenConfig->clientId = $clientId;
$this->originalTokenConfig->clientSecret = $clientSecret;
$this->originalTokenConfig->tokenUrl = $tokenUrl;
$this->originalTokenConfig->browser = $browser;
$this->tokenConfig = clone $this->originalTokenConfig;
}
/**
* @param string $clientId
*
* @return $this
*/
public function withClientId($clientId)
{
$this->tokenConfig->clientId = $clientId;
return $this;
}
/**
* @param string $clientSecret
*
* @return $this
*/
public function withClientSecret($clientSecret)
{
$this->tokenConfig->clientSecret = $clientSecret;
return $this;
}
/**
* @param string $tokenUrl
*
* @return $this
*/
public function withTokenUrl($tokenUrl)
{
$this->tokenConfig->tokenUrl = $tokenUrl;
return $this;
}
/**
* Reset
*/
public function reset()
{
$this->tokenConfig = clone $this->originalTokenConfig;
}
/**
* @return Token
*/
public function create()
{
$token = new Token(
$this->tokenConfig->clientId,
$this->tokenConfig->clientSecret,
$this->tokenConfig->tokenUrl,
$this->tokenConfig->browser
);
$this->reset();
return $token;
}
}