setDescription('Execute a service') ->addArgument('type') ->addArgument('body') ->addOption('preserve-payload', 'p', InputOption::VALUE_NONE, 'Preserve temporary payload file'); return $this; } protected function doExecute(InputInterface $input, OutputInterface $output) { /** @var WorkerResolverInterface $workerResolver */ $workerResolver = $this->container['alchemy_worker.type_based_worker_resolver']; $type = $input->getArgument('type'); $body = file_get_contents($input->getArgument('body')); if ($body === false) { $output->writeln('Unable to read payload file'); return; } $body = json_decode($body, true); if (json_last_error() !== JSON_ERROR_NONE) { $output->writeln('Invalid message body'); return; } $worker = $workerResolver->getWorker($type, $body); $worker->process($body); if (! $input->getOption('preserve-payload')) { unlink($input->getArgument('body')); } } }