1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Example of retrieving an authentication token of the Amazon service. |
||
5 | * |
||
6 | * PHP version 5.4 |
||
7 | * |
||
8 | * @author Flávio Heleno <[email protected]> |
||
9 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
10 | */ |
||
11 | |||
12 | use OAuth\Common\Consumer\Credentials; |
||
13 | use OAuth\Common\Http\Client\CurlClient; |
||
14 | use OAuth\Common\Http\Exception\TokenResponseException; |
||
15 | use OAuth\Common\Storage\Session; |
||
16 | use OAuth\Helper\Example; |
||
0 ignored issues
–
show
|
|||
17 | use OAuth\OAuth2\Service\Amazon; |
||
18 | |||
19 | require_once __DIR__ . '/../bootstrap.php'; |
||
20 | |||
21 | $helper = new Example(); |
||
22 | $storage = new Session(); |
||
23 | $client = new CurlClient(); |
||
24 | |||
25 | $helper->setTitle('Amazon'); |
||
26 | if (empty($_GET)) { |
||
27 | echo $helper->getContent(); |
||
28 | } elseif (!empty($_GET['key']) && !empty($_GET['secret']) && $_GET['oauth'] !== 'redirect') { |
||
29 | $credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl()); |
||
30 | $service = new Amazon($credentials, $client, $storage); |
||
31 | echo $helper->getHeader(); |
||
32 | echo '<a href="' . $service->getAuthorizationUri() . '">get access token</a>'; |
||
33 | echo $helper->getFooter(); |
||
34 | } elseif (!empty($_GET['code'])) { |
||
35 | $credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl()); |
||
36 | $service = new Amazon($credentials, $client, $storage); |
||
37 | |||
38 | echo $helper->getHeader(); |
||
39 | |||
40 | try { |
||
41 | $token = $service->requestAccessToken($_GET['code']); |
||
42 | echo 'access token: ' . $token->getAccessToken(); |
||
43 | } catch (TokenResponseException $exception) { |
||
44 | $helper->getErrorMessage($exception); |
||
45 | } |
||
46 | echo $helper->getFooter(); |
||
47 | } |
||
48 |
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: