Sto tentando di creare un comando console symfony per eseguire un endpoint.Symfony 2 - Chiamare un metodo controller dal comando console
BillingBundle/Comando/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");
}
}
?>
sto provando a chiamare e endpoint definito
BillingBundle/Servizi/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
}
Funziona bene quando chiamo il punto finale/rejectLines usando POSTman. Tuttavia, io non sono molto sicuro di come faccio a chiamare dalla console di comando in modo tale che quando chiamo
php app/console cron: rejectLines
funziona.
Questo è quello che voglio ottenere.
$cron = new SalesOrderService();
$cron->rejectSalesOrderLines();
Tuttavia, perché la classe SalesOrderService ha alcuni argomenti passati al __construct, io non sono del tutto sicuro di come posso passarlo al momento della chiamata attraverso la linea di comando. Qualche idea ?
Hai provato a farlo funzionare in CLI? Qual è l'output? –