私はこれに対する回避策を見つけました.
Command
独自のバンドルの 1 つ (または専用のバンドルはあなた次第) に追加することで、Doctrine コマンドを簡単にサブクラス化できます。たとえば、dbal:import
コマンドを有効にするには、次を使用します。
namespace Acme\Bundle\AcmeBundle\Command\Doctrine;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
class ImportCommand extends \Doctrine\DBAL\Tools\Console\Command\ImportCommand {
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getApplication()->getKernel()->getContainer();
$doctrine = $container->get('doctrine');
$em = $doctrine->getEntityManager();
$db = $em->getConnection();
$helperSet = $this->getHelperSet();
$helperSet->set( new ConnectionHelper( $db ), 'db' );
$helperSet->set( new EntityManagerHelper( $em ), 'em' );
parent::execute( $input, $output );
}
}
ご覧のとおり、元のコマンドをサブクラス化するだけです。データベース構成は Symfony によって管理されるため、コンテナーを介してエンティティーマネージャーを取得する必要があります。を更新したら、HelperSet
実行を親クラスに戻します。