Próbuję utworzyć polecenie konsoli symfony, aby uruchomić punkt końcowy.Symfony 2 - Wywołanie metody kontrolera z polecenia konsoli
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");
}
}
?>
Próbuję zadzwonić i punkt końcowy zdefiniowano w
BillingBundle/Usługi/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
}
Działa to dobrze, gdy wywołuję punkt końcowy/rejectLines za pomocą POSTman. Jednak nie jestem pewien, w jaki sposób mogę zadzwonić z poleceniem konsoli tak, że gdy zgłoszę
php app/console cron: rejectLines
to działa.
Oto, co chcę osiągnąć.
$cron = new SalesOrderService();
$cron->rejectSalesOrderLines();
Jednakże, ponieważ klasa SalesOrderService ma jakieś argumenty przekazane do __construct, nie jestem pewien, w jaki sposób mogę przekazać ją podczas rozmowy przez polecenia. Dowolny pomysł ?
Czy próbowałeś uruchomić go w CLI? Co to jest wyjście? –