1 | <?php |
||
2 | |||
3 | use OAuth\Common\Consumer\Credentials; |
||
4 | use OAuth\Common\Http\Client\CurlClient; |
||
5 | use OAuth\Common\Http\Exception\TokenResponseException; |
||
6 | use OAuth\Common\Storage\Session; |
||
7 | use OAuth\Helper\Example; |
||
0 ignored issues
–
show
|
|||
8 | use OAuth\OAuth2\Service\Vkontakte; |
||
9 | |||
10 | require_once __DIR__ . '/../bootstrap.php'; |
||
11 | |||
12 | $helper = new Example(); |
||
13 | $storage = new Session(); |
||
14 | $client = new CurlClient(); |
||
15 | $helper->setTitle('Vkontakte'); |
||
16 | if (empty($_GET)) { |
||
17 | echo $helper->getContent(); |
||
18 | } elseif (!empty($_GET['key']) && !empty($_GET['secret']) && $_GET['oauth'] !== 'redirect') { |
||
19 | $credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl()); |
||
20 | $vkService = new Vkontakte($credentials, $client, $storage); |
||
21 | echo $helper->getHeader(); |
||
22 | echo '<a href="' . $vkService->getAuthorizationUri() . '">get access token</a>'; |
||
23 | echo $helper->getFooter(); |
||
24 | } elseif (!empty($_GET['code'])) { |
||
25 | $credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl()); |
||
26 | $vkService = new Vkontakte($credentials, $client, $storage); |
||
27 | |||
28 | echo $helper->getHeader(); |
||
29 | |||
30 | try { |
||
31 | $token = $vkService->requestAccessToken($_GET['code']); |
||
32 | echo 'access token: ' . $token->getAccessToken(); |
||
33 | } catch (TokenResponseException $exception) { |
||
34 | $helper->getErrorMessage($exception); |
||
35 | } |
||
36 | echo $helper->getFooter(); |
||
37 | } |
||
38 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: