Files
afup/sources/AppBundle/Command/TwitterBotCommand.php
Jean-Baptiste Nahan ab63791ce1 correction de la configuration (#767)
* correction de la configuration
* renommage des services pour preparer SF4
* remplacement des noms de service par les noms de classe
* ajout commentaire pour les services n'ayant pas de nom sous forme de nom de classe
2019-04-03 23:13:27 +02:00

72 lines
2.0 KiB
PHP

<?php
namespace AppBundle\Command;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\PlanningRepository;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Repository\TweetRepository;
use AppBundle\VideoNotifier\Runner;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class TwitterBotCommand extends ContainerAwareCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('twitter-bot:run')
->addOption('event-path', null, InputOption::VALUE_REQUIRED);
;
}
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
$ting = $container->get('ting');
$runner = new Runner(
$ting->get(PlanningRepository::class),
$ting->get(TalkRepository::class),
$ting->get(EventRepository::class),
$ting->get(SpeakerRepository::class),
$ting->get(TweetRepository::class),
$container->get(\TwitterAPIExchange::class)
);
$runner->execute($this->getEventFilter($input));
}
/**
* @param InputInterface $input
*
* @return null
*/
protected function getEventFilter(InputInterface $input)
{
if (null === ($eventPath = $input->getOption('event-path'))) {
return null;
}
$event = $this
->getContainer()
->get('ting')
->get(EventRepository::class)
->getByPath($eventPath)
;
if (null === $event) {
throw new \InvalidArgumentException("L'événement sur lequel filter n'a pas été trouvé");
}
return $event;
}
}