drupal-meetups-twitterbot/src/Command/FetchTweetsCommand.php

54 lines
1.3 KiB
PHP
Raw Normal View History

2019-01-10 13:00:09 +00:00
<?php
namespace App\Command;
2019-01-10 23:51:40 +00:00
use App\Model\Tweet;
2019-01-10 14:17:08 +00:00
use App\Service\TweetFetcher;
2019-01-10 13:00:09 +00:00
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class FetchTweetsCommand extends Command
{
protected static $defaultName = 'app:fetch-tweets';
2019-01-10 14:07:59 +00:00
/**
* @var \App\Service\TweetFetcher
*/
private $tweetFetcher;
public function __construct(TweetFetcher $tweetFetcher)
{
parent::__construct();
$this->tweetFetcher = $tweetFetcher;
}
2019-01-10 13:00:09 +00:00
protected function configure()
{
$this
->setDescription('Add a short description for your command')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
2019-01-10 22:57:07 +00:00
$io->table(
['Tweet', 'Author', 'Created', 'ID'],
2019-01-10 23:51:40 +00:00
$this->tweetFetcher->getTweets()->map(function (Tweet $tweet) {
2019-01-10 22:57:07 +00:00
return [
2019-01-10 23:51:40 +00:00
$tweet->getText(),
$tweet->getAuthor(),
$tweet->getCreated(),
$tweet->getId(),
2019-01-10 22:57:07 +00:00
];
})->all()
);
2019-01-10 13:00:09 +00:00
}
}