繁体   English   中英

在PHP脚本中运行Symfony2命令(propel:build)

[英]Running Symfony2 command (propel:build) within PHP script

我想在PHP脚本中运行控制台命令。 通常,它是通过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());

但是我的输出是[Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException] You have requested a non-existent service "propel.configuration"

我该如何解决?

我不确定100%,但是我认为问题在于您要尽早访问服务容器。 尝试在$application->run($input, $output);之后访问它$application->run($input, $output); 该容器应该可以通过$kernel->getContainer()进行访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM