[英]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.