|
6 | 6 | * PHP version 5.4 |
7 | 7 | * |
8 | 8 | * @author Mukunda Johnson (mukunda.com) |
9 | | - * @copyright Copyright (c) 2012 The authors |
10 | 9 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
11 | 10 | */ |
12 | 11 |
|
13 | | -use OAuth\OAuth2\Service\BattleNet; |
14 | | -use OAuth\Common\Storage\Session; |
15 | 12 | use OAuth\Common\Consumer\Credentials; |
16 | 13 | use OAuth\Common\Http\Uri\Uri; |
| 14 | +use OAuth\Common\Storage\Session; |
| 15 | +use OAuth\OAuth2\Service\BattleNet; |
17 | 16 |
|
18 | 17 | /** --------------------------------------------------------------------------- |
19 | | - * Bootstrap the example |
| 18 | + * Bootstrap the example. |
20 | 19 | */ |
21 | 20 | require_once __DIR__ . '/bootstrap.php'; |
22 | 21 |
|
23 | | -if( empty( $_GET['code'] ) && !isset($_GET['go'] )) { |
| 22 | +if (empty($_GET['code']) && !isset($_GET['go'])) { |
24 | 23 |
|
25 | 24 | // Empty query; show the startup page. |
26 | | - |
| 25 | + |
27 | 26 | echo ' |
28 | 27 | |
29 | 28 | <p>Sign-in using Battle.net. Please pick your region:</p> |
|
37 | 36 | </p> |
38 | 37 | |
39 | 38 | '; |
40 | | - |
| 39 | + |
41 | 40 | die(); |
42 | 41 | } |
43 | 42 |
|
|
54 | 53 | $servicesCredentials['battlenet']['secret'], |
55 | 54 | $currentUri->getAbsoluteUri() |
56 | 55 | ); |
57 | | - |
58 | | -$region = isset($_GET['region']) ? $_GET['region'] : ""; |
59 | 56 |
|
60 | | -$region_map = array( |
| 57 | +$region = $_GET['region'] ?? ''; |
| 58 | + |
| 59 | +$region_map = [ |
61 | 60 | 'us' => BattleNet::API_URI_US, // USA - this is the default if you omit the base API URI. |
62 | 61 | 'eu' => BattleNet::API_URI_EU, // Europe |
63 | 62 | 'kr' => BattleNet::API_URI_KR, // Korea |
64 | 63 | 'tw' => BattleNet::API_URI_TW, // Taiwan |
65 | 64 | 'cn' => BattleNet::API_URI_CN, // China |
66 | | -); |
| 65 | +]; |
67 | 66 |
|
68 | 67 | // Get base API URI from region. |
69 | | -$apiuri = isset( $region_map[$region] ) ? new Uri( $region_map[$region] ) : null; |
| 68 | +$apiuri = isset($region_map[$region]) ? new Uri($region_map[$region]) : null; |
70 | 69 |
|
71 | 70 | // Without any scopes, we can get their BattleTag. |
72 | | -$scopes = array(); |
| 71 | +$scopes = []; |
73 | 72 |
|
74 | | -$battlenetService = $serviceFactory->createService( |
75 | | - 'battlenet', $credentials, $storage, $scopes, $apiuri ); |
| 73 | +$battlenetService = $serviceFactory->createService( |
| 74 | + 'battlenet', $credentials, $storage, $scopes, $apiuri); |
76 | 75 |
|
77 | | -if( !empty($_GET['code']) ) { |
| 76 | +if (!empty($_GET['code'])) { |
78 | 77 | // This was a callback request from Battle.net, get the token |
79 | | - $token = $battlenetService->requestAccessToken( $_GET['code'] ); |
| 78 | + $token = $battlenetService->requestAccessToken($_GET['code']); |
80 | 79 |
|
81 | 80 | // See https://dev.battle.net/io-docs for OAuth request types. |
82 | 81 | // |
83 | 82 | // Without any scopes specified, we can get their BattleTag. |
84 | | - $result = json_decode( $battlenetService->request('/account/user') ); |
| 83 | + $result = json_decode($battlenetService->request('/account/user')); |
85 | 84 |
|
86 | 85 | echo "Your BattleTag is \"$result->battletag\"."; |
87 | | - |
88 | | -} elseif( isset($_GET['go']) ) { |
89 | | - |
| 86 | +} elseif (isset($_GET['go'])) { |
90 | 87 | $url = $battlenetService->getAuthorizationUri(); |
91 | | - header( "Location: $url" ); |
92 | | - |
| 88 | + header("Location: $url"); |
93 | 89 | } |
0 commit comments