我正在尝试创建一个symfony控制台命令来执行一个端点。Symfony 2 - 从控制台命令调用控制器方法
BillingBundle /命令/ 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");
}
}
?>
我试图打电话和
定义端点BillingBundle /服务/ 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
}
当我使用POSTman调用结束点/ rejectLines时,此工作正常。不过,我不太清楚如何从控制台命令调用,当我打电话
PHP应用程序/控制台的cron这样:rejectLines
它的工作原理。
这就是我想要达到的。
$cron = new SalesOrderService();
$cron->rejectSalesOrderLines();
然而,由于SalesOrderService类有一些参数传递给__construct,我不太清楚,通过命令行调用时,我如何能够通过。任何想法 ?
您是否尝试过在命令行运行呢?什么是输出? –