| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
-
- namespace App\Command;
-
- use App\Service\MailFetcher;
- use Symfony\Component\Console\Attribute\AsCommand;
- 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;
-
- #[AsCommand(
- name: 'app:fetch-emails',
- description: 'Fetch emails and process them',
- )]
- class FetchEmailsCommand extends Command
- {
- private MailFetcher $mailFetcher;
-
- public function __construct(MailFetcher $mailFetcher)
- {
- parent::__construct();
- $this->mailFetcher = $mailFetcher;
- }
-
- protected function configure(): void
- {
- $this
- ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
- ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description');
- }
-
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- $io = new SymfonyStyle($input, $output);
- $arg1 = $input->getArgument('arg1');
-
- if ($arg1) {
- $io->note(sprintf('You passed an argument: %s', $arg1));
- }
-
- if ($input->getOption('option1')) {
- // ...
- }
-
- $this->mailFetcher->fetchNewEmails();
-
-
- $io->success('You have a new command! Now make it your own! Pass --help to see your options.');
-
- return Command::SUCCESS;
- }
- }
|