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

52 lines
1.2 KiB
PHP
Raw Normal View History

2019-01-10 13:00:09 +00:00
<?php
namespace App\Command;
2019-01-11 21:15:43 +00:00
use App\Entity\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\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
2019-01-10 13:00:09 +00:00
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)
2019-01-10 14:07:59 +00:00
{
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);
$io->table(
['Tweet', 'Author', 'Created', 'ID'],
$this->tweetFetcher->getTweets()->map(function (Tweet $tweet) {
return [
$tweet->getText(),
$tweet->getAuthor(),
$tweet->getCreated(),
$tweet->getId(),
];
})->all()
);
2019-01-10 13:00:09 +00:00
}
}