1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Beñat Espiña <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BenatEspina\StackExchangeApiClient\Api; |
13
|
|
|
|
14
|
|
|
use BenatEspina\StackExchangeApiClient\Http\Http; |
15
|
|
|
use BenatEspina\StackExchangeApiClient\Serializer\AccessTokenSerializer; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The access token api class. |
19
|
|
|
* |
20
|
|
|
* @author Beñat Espiña <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class AccessTokenApi |
23
|
|
|
{ |
24
|
|
|
const URL = 'access-tokens/'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Immediately expires the access tokens passed. |
28
|
|
|
* |
29
|
|
|
* More info: https://api.stackexchange.com/docs/invalidate-access-tokens |
30
|
|
|
* |
31
|
|
|
* @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token |
32
|
|
|
* @param array $params QueryString parameter(s), it admits page and pagesize; by default is null |
33
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
34
|
|
|
* |
35
|
|
|
* @return array |
|
|
|
|
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function invalidate($accessTokens, array $params = [], $serialize = true) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$response = Http::instance()->get( |
40
|
|
|
self::URL . (is_array($accessTokens) ? implode(';', $accessTokens) : $accessTokens) . '/invalidate', $params |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
return $serialize === true ? AccessTokenSerializer::instance()->serialize($response) : $response; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Reads the properties for a set of access tokens. |
48
|
|
|
* |
49
|
|
|
* More info: https://api.stackexchange.com/docs/read-access-tokens |
50
|
|
|
* |
51
|
|
|
* @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token |
52
|
|
|
* @param array $params QueryString parameter(s), it admits page and pagesize; by default is null |
53
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
54
|
|
|
* |
55
|
|
|
* @return array |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
public function getOfToken($accessTokens, array $params = [], $serialize = true) |
58
|
|
|
{ |
59
|
|
|
$response = Http::instance()->get( |
60
|
|
|
self::URL . (is_array($accessTokens) ? implode(';', $accessTokens) : $accessTokens), $params |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
return $serialize === true ? AccessTokenSerializer::instance()->serialize($response) : $response; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Allows an application to de-authorize itself for a set of users. |
68
|
|
|
* |
69
|
|
|
* More info: https://api.stackexchange.com/docs/application-de-authenticate |
70
|
|
|
* |
71
|
|
|
* @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token |
72
|
|
|
* @param array $params QueryString parameter(s), it admits page and pagesize; by default is null |
73
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
74
|
|
|
* |
75
|
|
|
* @return array |
|
|
|
|
76
|
|
|
*/ |
77
|
|
|
public function deAuthenticate($accessTokens, array $params = [], $serialize = true) |
78
|
|
|
{ |
79
|
|
|
$response = Http::instance()->get( |
80
|
|
|
self::URL . (is_array($accessTokens) ? implode(';', $accessTokens) : $accessTokens) . '/de-authenticate', $params |
|
|
|
|
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
return $serialize === true ? AccessTokenSerializer::instance()->serialize($response) : $response; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.