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-11 21:16:48 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
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;
|
|
|
|
|
|
|
|
class FetchTweetsCommand extends Command
|
|
|
|
{
|
|
|
|
protected static $defaultName = 'app:fetch-tweets';
|
|
|
|
|
2019-01-10 14:07:59 +00:00
|
|
|
/**
|
|
|
|
* @var \App\Service\TweetFetcher
|
|
|
|
*/
|
|
|
|
private $tweetFetcher;
|
|
|
|
|
2019-01-11 21:16:48 +00:00
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\EntityManagerInterface
|
|
|
|
*/
|
|
|
|
private $entityManager;
|
|
|
|
|
|
|
|
public function __construct(TweetFetcher $tweetFetcher, EntityManagerInterface $entityManager)
|
2019-01-10 14:07:59 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->tweetFetcher = $tweetFetcher;
|
2019-01-11 21:16:48 +00:00
|
|
|
$this->entityManager = $entityManager;
|
2019-01-10 14:07:59 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2019-01-11 21:16:48 +00:00
|
|
|
$this->tweetFetcher->getTweets()->each(function (Tweet $tweet) {
|
|
|
|
$this->entityManager->persist($tweet);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->entityManager->flush();
|
2019-01-10 13:00:09 +00:00
|
|
|
}
|
|
|
|
}
|