Issues (144)

examples/provider/ustream.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * Example of retrieving an authentication token of the Ustream service.
5
 *
6
 * PHP version 5.4
7
 *
8
 * @author     Attila Gonda <[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
This use statement conflicts with another class in this namespace, Example. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use OAuth\OAuth2\Service\Ustream;
18
19
require_once __DIR__ . '/../bootstrap.php';
20
21
$helper = new Example();
22
$storage = new Session();
23
$client = new CurlClient();
24
25
$helper->setTitle('Instagram');
26
27
if (empty($_GET)) {
28
    echo $helper->getContent();
29
} elseif (!empty($_GET['key']) && !empty($_GET['secret']) && $_GET['oauth'] !== 'redirect') {
30
    $credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
31
    $service = new Ustream($credentials, $client, $storage);
32
    echo $helper->getHeader();
33
    echo '<a href="' . $service->getAuthorizationUri() . '">get access token</a>';
34
    echo $helper->getFooter();
35
} elseif (!empty($_GET['code'])) {
36
    $credentials = new Credentials($_GET['key'], $_GET['secret'], $helper->getCurrentUrl());
37
    $service = new Ustream($credentials, $client, $storage);
38
39
    echo $helper->getHeader();
40
41
    try {
42
        $token = $service->requestAccessToken($_GET['code']);
43
        echo 'access token: ' . $token->getAccessToken();
44
    } catch (TokenResponseException $exception) {
45
        $helper->getErrorMessage($exception);
46
    }
47
    echo $helper->getFooter();
48
}
49