[英]Running Symfony2 command (propel:build) within PHP script
I want to run a console command within a PHP script. 我想在PHP脚本中运行控制台命令。 Usually it's done via the CLI, so I tried to edit it and the result is as follows:
通常,它是通过CLI完成的,因此我尝试对其进行编辑,结果如下:
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Propel\PropelBundle\Command\BuildCommand;
set_time_limit(0);
require_once '/home/core/site/app/bootstrap.php.cache';
require_once '/home/core/site/app/AppKernel.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$application = new Application($kernel);//->find('propel:build');
$application->setAutoExit(false);
$application->add(new BuildCommand());
$input = new ArrayInput(array('command' => 'propel:build', '--insert-sql' => true));
$output = new BufferedOutput();
$application->run($input, $output);
echo '<pre>';
var_dump($output->fetch());
But my output is [Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException] You have requested a non-existent service "propel.configuration"
. 但是我的输出是
[Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException] You have requested a non-existent service "propel.configuration"
。
How can I solve this? 我该如何解决?
I'm not 100% sure, but I think the problem is that you access the services container to early. 我不确定100%,但是我认为问题在于您要尽早访问服务容器。 Try accessing it after
$application->run($input, $output);
尝试在
$application->run($input, $output);
之后访问它$application->run($input, $output);
. 。 The container should be accessible via
$kernel->getContainer()
. 该容器应该可以通过
$kernel->getContainer()
进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.