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

时间:2014-08-11 15:04:39

标签: php symfony propel

我想在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"

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我不是100%肯定,但我认为问题是您提前访问服务容器。尝试在$application->run($input, $output);之后访问它。该容器应可通过$kernel->getContainer()访问。