コード例 #1
0
ファイル: AlertCommand.php プロジェクト: maidmaid/cffie
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $date = new \DateTime($input->getArgument('time'));
     // Get departure/arrival stops
     $departure = $this->cff->getStop($input->getArgument('departure'));
     $arrival = $this->cff->getStop($input->getArgument('arrival'));
     $output->write(sprintf('%s -> %s at %s : ', $departure['value'], $arrival['value'], $date->format('H:s')));
     $times = $this->cff->query($departure, $arrival, $date);
     $times = array_filter($times, function ($value) use($date) {
         return new \DateTime($value['departure']) == $date;
     });
     if ($infos = current($times)['infos']) {
         $output->writeln(sprintf('<comment>%s</comment>', $infos));
         // Create the Transport
         $transport = \Swift_SmtpTransport::newInstance($input->getOption('host'), $input->getOption('port'), $input->getOption('security'))->setUsername($input->getOption('username'))->setPassword($input->getOption('password'));
         $mailer = \Swift_Mailer::newInstance($transport);
         // Create a message
         $message = \Swift_Message::newInstance($infos)->setFrom(array($input->getOption('username') => 'CFFie'))->setTo(array($input->getOption('to')))->setBody(sprintf("%s -> %s at %s\nCFFie", $departure['value'], $arrival['value'], $date->format('H:m')));
         // Send the message
         $result = $mailer->send($message);
         if ($result) {
             $this->output->success($input->getOption('to') . ' alerted !');
         }
     } else {
         $output->writeln('<info>ok</info>');
     }
 }
コード例 #2
0
ファイル: QueryCommand.php プロジェクト: maidmaid/cffie
 private function getStop($value, $question = 'Which station ?')
 {
     $stops = $this->cff->getStop($value, false);
     if ($stops[0]['value'] != $value) {
         $values = array_column($stops, 'value');
         $value = $this->io->choice($question, $values, $stops[0]['value']);
         $key = array_search($value, $values);
         return $stops[$key];
     }
     return $stops[0];
 }