I am trying to create a symfony console command to execute an end point.
BillingBundle/Command/RejectCommand.php
<?php
namespace BillingBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class RejectCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('cron:rejectLines')
->setDescription('Executes the RejectLines cron');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("Starting the cron");
// Call the method here
$output->writeln("Cron completed");
}
}
?>
I am trying to call and endpoint defined in
BillingBundle/Services/SalesOrderService.php
/**
* @InjectParams({
* "repository" = @Inject("billing.repository.sales_order"),
* "sapInterface" = @Inject("external.sap_sales_order_interface"),
* "articleService" = @Inject("stream_one.product.interface.solution_store_product_service"),
* "logger" = @Inject("logger")
* })
*/
public function __construct(SalesOrderRepositoryInterface $repository, SapSalesOrderInterface $sapInterface, ArticleService $articleService, Logger $logger) {
$this->repository = $repository;
$this->sapInterface = $sapInterface;
$this->articleService = $articleService;
$this->logger = $logger;
}
/**
* CRON: Reject lines
*
* @Post("/rejectLines", name="reject_lines_post")
*/
public function rejectSalesOrderLines() {
// do some stuff and quit silently
}
This works fine when I call the end point /rejectLines using POSTman. However, I am not quite sure how do I call from console command so that when I call
php app/console cron:rejectLines
it works.
This is what I wanna achieve.
$cron = new SalesOrderService();
$cron->rejectSalesOrderLines();
However, because SalesOrderService class has some arguments passed to the __construct, I am not quite sure how I can pass it when calling through the commandline. Any idea ?