1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Twitter\Console; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
7
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
8
|
|
|
use Symfony\Component\Console\Exception\RuntimeException; |
9
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Question\Question; |
13
|
|
|
use Twitter\API\Exception\TwitterException; |
14
|
|
|
use Twitter\API\REST\TwitterApiGateway; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class AuthenticationCommand |
18
|
|
|
* |
19
|
|
|
* @package TwitterStream\Console |
20
|
|
|
* |
21
|
|
|
* @codeCoverageIgnore |
22
|
|
|
*/ |
23
|
|
|
class AuthenticationCommand extends Command |
24
|
|
|
{ |
25
|
|
|
/** @var TwitterApiGateway */ |
26
|
|
|
private $adapter; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* AuthenticationCommand constructor. |
30
|
|
|
* |
31
|
|
|
* @param TwitterApiGateway $adapter |
32
|
|
|
* |
33
|
|
|
* @throws LogicException |
34
|
|
|
*/ |
35
|
|
|
public function __construct(TwitterApiGateway $adapter, $name = null) |
36
|
|
|
{ |
37
|
|
|
parent::__construct($name); |
38
|
|
|
|
39
|
|
|
$this->adapter = $adapter; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Configures the command |
44
|
|
|
*/ |
45
|
|
|
protected function configure() |
46
|
|
|
{ |
47
|
|
|
$this->setDescription('Authenticate'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Code executed when command invoked |
52
|
|
|
* |
53
|
|
|
* @param InputInterface $input |
54
|
|
|
* @param OutputInterface $output |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
* |
58
|
|
|
* @throws RuntimeException |
59
|
|
|
* @throws LogicException |
60
|
|
|
* @throws InvalidArgumentException |
61
|
|
|
* @throws TwitterException |
62
|
|
|
*/ |
63
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
64
|
|
|
{ |
65
|
|
|
$authUrl = $this->adapter->getAuthenticationUrl(); |
66
|
|
|
|
67
|
|
|
/** @var QuestionHelper $helper */ |
68
|
|
|
$helper = $this->getHelper('question'); |
69
|
|
|
$verificationCode = $helper->ask( |
70
|
|
|
$input, |
71
|
|
|
$output, |
72
|
|
|
new Question('Visit <info>' . $authUrl . '</info> and enter verification code: ') |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$authToken = $this->adapter->getAuthenticationToken($verificationCode); |
76
|
|
|
|
77
|
|
|
$output->writeln('Token : <info>' . $authToken->getToken() . '</info>'); |
78
|
|
|
$output->writeln('Secret : <info>' . $authToken->getSecret() . '</info>'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|