1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Risan\OAuth1\Request; |
4
|
|
|
|
5
|
|
|
use Risan\OAuth1\Credentials\TemporaryCredentials; |
6
|
|
|
|
7
|
|
|
class RequestFactory implements RequestFactoryInterface |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The AuthorizationHeaderInterface instance. |
11
|
|
|
* |
12
|
|
|
* @var \Risan\OAuth1\Request\AuthorizationHeaderInterface |
13
|
|
|
*/ |
14
|
|
|
protected $authorizationHeader; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The UriParserInterface instance. |
18
|
|
|
* |
19
|
|
|
* @var \Risan\OAuth1\Request\UriParserInterface |
20
|
|
|
*/ |
21
|
|
|
protected $uriParser; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Create the new instance of RequestFactory class. |
25
|
|
|
* |
26
|
|
|
* @param \Risan\OAuth1\Request\AuthorizationHeaderInterface $authorizationHeader |
27
|
|
|
* @param \Risan\OAuth1\Request\UriParserInterface $uriParser |
28
|
|
|
*/ |
29
|
7 |
|
public function __construct(AuthorizationHeaderInterface $authorizationHeader, UriParserInterface $uriParser) |
30
|
|
|
{ |
31
|
7 |
|
$this->authorizationHeader = $authorizationHeader; |
32
|
7 |
|
$this->uriParser = $uriParser; |
33
|
7 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritDoc} |
37
|
|
|
*/ |
38
|
1 |
|
public function getAuthorizationHeader() |
39
|
|
|
{ |
40
|
1 |
|
return $this->authorizationHeader; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritDoc} |
45
|
|
|
*/ |
46
|
1 |
|
public function getConfig() |
47
|
|
|
{ |
48
|
1 |
|
return $this->authorizationHeader->getConfig(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritDoc} |
53
|
|
|
*/ |
54
|
1 |
|
public function getUriParser() |
55
|
|
|
{ |
56
|
1 |
|
return $this->uriParser; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
1 |
|
public function createForTemporaryCredentials() |
63
|
|
|
{ |
64
|
1 |
|
return $this->create('POST', $this->getConfig()->getTemporaryCredentialsUri(), [ |
|
|
|
|
65
|
|
|
'headers' => [ |
66
|
1 |
|
'Authorization' => $this->authorizationHeader->forTemporaryCredentials(), |
67
|
|
|
], |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritDoc} |
73
|
|
|
*/ |
74
|
1 |
|
public function buildAuthorizationUri(TemporaryCredentials $temporaryCredentials) |
75
|
|
|
{ |
76
|
1 |
|
return $this->uriParser->appendQueryParameters( |
77
|
1 |
|
$this->getConfig()->getAuthorizationUri(), |
78
|
1 |
|
['oauth_token' => $temporaryCredentials->getIdentifier()] |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
1 |
|
public function createForTokenCredentials(TemporaryCredentials $temporaryCredentials, $verificationCode) |
86
|
|
|
{ |
87
|
1 |
|
return $this->create('POST', $this->getConfig()->getTokenCredentialsUri(), [ |
|
|
|
|
88
|
|
|
'headers' => [ |
89
|
1 |
|
'Authorization' => $this->authorizationHeader->forTokenCredentials($temporaryCredentials, $verificationCode), |
90
|
|
|
], |
91
|
|
|
'form_params' => [ |
92
|
1 |
|
'oauth_verifier' => $verificationCode, |
93
|
|
|
], |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Create a new instance of Request class. |
99
|
|
|
* |
100
|
|
|
* @param string $method |
101
|
|
|
* @param strin $uri |
102
|
|
|
* @param array $options [description] |
103
|
|
|
* @return \Risan\OAuth1\Request\RequestInterface |
104
|
|
|
*/ |
105
|
|
|
public function create($method, $uri, array $options = []) |
106
|
|
|
{ |
107
|
|
|
return new Request($method, $uri, $options); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: