我正在尝试使用 PHP 5.3.10 在 Docker 下运行 Symfony 命令。当我到达像这样的线时
class Data{
public function prepareData(){
echo 'before getContainer';
$em = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection();
echo 'after getContainer';
}
}
它默默地失败了。
用于设置容器的 docker 命令是
docker run --network="host" -t -i -p 80:80 -v /srv/www/live/:/srv/www/live/ -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock bylexus/apache-php53 /bin/bash
在 Docker 容器中,我安装了 mysql,然后可以登录并查看本地系统上存在的数据库。
我在 Docker 容器中运行的 Symfony 命令就像
php app/console mytask:preparedata
从
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class PrepareDataCommand extends Command
{
protected function configure()
{
parent::configure();
$this->setName('mytask:preparedata');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->getHelper('Data')->prepareData();
}
}
它执行prepareData
功能。“getContainer 之后”从不回显,只是“getContainer 之前”。日志中没有任何内容,Apache、MySQL 或 Symfony。
你知道如何调试这个或如何让容器像它出现在 Docker 之外一样吗?
更新
我现在已经使用 phpbrew 对此进行了测试。它适用于 PHP 版本 5.6.30,但不适用于所需的 PHP 版本 5.3.10(与$em = $this->getContainer
上述相同的行停止)。奇怪的是,它也不适用于 phpbrew 中的 PHP 7.0.3。现在可能是关于 PHP 版本的 Symfony 或 Doctrine 相关问题吗?